mirror of
https://github.com/aws-actions/configure-aws-credentials.git
synced 2026-09-02 05:55:10 +09:00
Compare commits
652 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e7f100cf4c | |||
| bbbffeab00 | |||
| d6f5dc331b | |||
| 12014c0798 | |||
| 4ab3589ed2 | |||
| 99214aa688 | |||
| 217d17914b | |||
| 5548f3441b | |||
| 77cd089899 | |||
| dbacf3135e | |||
| 87eb0cf693 | |||
| acca2b1b20 | |||
| c329d242ce | |||
| c39f282697 | |||
| 8188bee95b | |||
| 477988d772 | |||
| 9a5ab5bbe8 | |||
| baa1fdfef9 | |||
| 4be0a3c167 | |||
| f85f964a2e | |||
| 6fddd0cf67 | |||
| 254d42c4b6 | |||
| 01e40c97bf | |||
| 48a00774d0 | |||
| 18e0298e7d | |||
| 36eb080f7f | |||
| 3d40fa4093 | |||
| 3cc0e19239 | |||
| e8614cfbf0 | |||
| 4684f47f89 | |||
| 48b8685c96 | |||
| fe6ad3af19 | |||
| 2520c5e921 | |||
| bc1093db1d | |||
| ffde832a1d | |||
| 707acd96f6 | |||
| a7c33ae483 | |||
| 713aaabfec | |||
| e6e8eba750 | |||
| 58e7c47adf | |||
| f35a7d7d7e | |||
| 3884f59ecd | |||
| e0ba768507 | |||
| 6795889618 | |||
| 29d1be3027 | |||
| ef734cca81 | |||
| 7521c55910 | |||
| c0e2737f14 | |||
| dbd503f368 | |||
| 18a236fbd1 | |||
| 1ab31502aa | |||
| 1fb495c4b2 | |||
| 1e8fec8ea1 | |||
| a388f23f7d | |||
| 3f7e1b63d7 | |||
| e35449909c | |||
| 958a80fc34 | |||
| 540d0c13ae | |||
| 07ada0fe07 | |||
| f8d4eb68a9 | |||
| 8d52d05d7a | |||
| 681892c11b | |||
| dc2353e57a | |||
| 61f50f630f | |||
| c36525a567 | |||
| 39d1702721 | |||
| 4cfda40a13 | |||
| 8856e12f3a | |||
| 64d8e82527 | |||
| 78f374f6d1 | |||
| d979d5b3a7 | |||
| d4a9acd8d3 | |||
| fc44f4ae40 | |||
| 0b8336f1ba | |||
| 8c5bf33eed | |||
| 53df0c1c32 | |||
| c2c55827d2 | |||
| bd0031d7c3 | |||
| 6ab499a698 | |||
| bc94895858 | |||
| 934ca25ed2 | |||
| 2141953f88 | |||
| bee39e8d77 | |||
| 21c0950dc0 | |||
| 94fd6c27a4 | |||
| 3c8d2af9dc | |||
| ee2d8e963b | |||
| 66e76254c4 | |||
| c36c0e55fd | |||
| 59c3fbfdaa | |||
| 5e19c1aa7a | |||
| aa48afa741 | |||
| 3e32d92984 | |||
| 795d57b736 | |||
| 8ff6de5203 | |||
| 3436a392ac | |||
| 3c894dabff | |||
| 787075d425 | |||
| 80269b713c | |||
| 1f08c8a67c | |||
| 930440c681 | |||
| d3bef17c22 | |||
| 61dcf734bf | |||
| ff6a0a0749 | |||
| 30a5c4561c | |||
| 000d6227cc | |||
| c315e354eb | |||
| 7945953394 | |||
| 870695bc36 | |||
| ec43ad8ccf | |||
| ec61189d14 | |||
| 81676eb9eb | |||
| dc64d28371 | |||
| bc0a50afbe | |||
| 9ea6412aba | |||
| 0a8759496b | |||
| a7f0c828ac | |||
| e6bb6e5ff3 | |||
| 11b1c58b24 | |||
| 51635dbf41 | |||
| 8d0763f1dd | |||
| 563c6001b1 | |||
| 86ccf31ce5 | |||
| 75adeddc6d | |||
| 84e4970378 | |||
| f86e2d2212 | |||
| c256fd5d4c | |||
| c422da5be3 | |||
| 21cbb61e80 | |||
| 118f2eabc7 | |||
| 8c3df7a7e3 | |||
| ea65c961f1 | |||
| ed95fff515 | |||
| 8f2e168fe8 | |||
| 7a319c378c | |||
| b1257c4001 | |||
| e08afaa6ae | |||
| 668d1470ed | |||
| 24d6c03371 | |||
| 97361f40d9 | |||
| b2e4eaa23d | |||
| 615659e46e | |||
| 2bb9df827e | |||
| 2ab6fc87e4 | |||
| f8de47bf3e | |||
| 0820d92983 | |||
| 9d1c42024f | |||
| b6772acfeb | |||
| 33712a4c0c | |||
| 4a69b64afd | |||
| 5b448139a8 | |||
| 589732a070 | |||
| 01320c3462 | |||
| c6fe21d5fb | |||
| 2e454faab9 | |||
| 915869ead1 | |||
| 29a5036ebe | |||
| 7642046d79 | |||
| 45ab090e10 | |||
| 3bd622937f | |||
| b47aa7bd72 | |||
| 4a7f27f713 | |||
| f98ea5fac2 | |||
| 2db830a320 | |||
| 6e631f05b2 | |||
| c575728438 | |||
| 96507ba8cf | |||
| c3b2204dd6 | |||
| c95c3899f6 | |||
| f487a3d994 | |||
| b9539eec90 | |||
| ac7d2f7df3 | |||
| e30d08aad1 | |||
| c00f62bf94 | |||
| 4ce2bbcf5d | |||
| 0f01265ceb | |||
| bb84b6db01 | |||
| b8de5565ca | |||
| 028c01e898 | |||
| 8df5847569 | |||
| d22a0f8af5 | |||
| f7b8181755 | |||
| c367a6acb0 | |||
| 7ceaf96edc | |||
| a7a2c1125c | |||
| 6e3375df07 | |||
| 98abed7841 | |||
| bf3adbbb94 | |||
| db43b8b90a | |||
| fc999da49a | |||
| 4f2ba7fe9c | |||
| a9717e6ab0 | |||
| 5638c55000 | |||
| 9260701d07 | |||
| 2a2d67de88 | |||
| 1f91feff98 | |||
| 5a45798cc2 | |||
| 03ca40259f | |||
| fdaa1bdaab | |||
| 76cd0519f8 | |||
| d8821142e5 | |||
| 455579b45d | |||
| aa67178d69 | |||
| 4b8f2761e5 | |||
| f63ad03df6 | |||
| 00e1ea3dc5 | |||
| 71fa3f4cf0 | |||
| eb0f73c987 | |||
| ab20c8bb65 | |||
| 65d5a3ae87 | |||
| acc79c2e07 | |||
| b1e95de918 | |||
| 86903cfb2e | |||
| 26e9ba52a0 | |||
| b5c9882977 | |||
| 5ffcf010cf | |||
| dffada93d8 | |||
| b61bf5b567 | |||
| 31f53c456e | |||
| 4df9a01ef6 | |||
| dad3c3ee8b | |||
| a12214142d | |||
| 7669a6d405 | |||
| 2763a9e234 | |||
| 731c99bf59 | |||
| 82399fd121 | |||
| 827e0dd2c7 | |||
| 92cde8da32 | |||
| 1b36ca57f6 | |||
| 50ecfdead0 | |||
| 66fa6511a5 | |||
| 96008b1ef1 | |||
| 40fe06d904 | |||
| 228103980f | |||
| ffde586b91 | |||
| 92ca50a768 | |||
| ac60232d49 | |||
| c2ee69e5ef | |||
| 756668eaa3 | |||
| d936e04b3a | |||
| bf7978d83a | |||
| a032176f30 | |||
| 9c1f8ca0da | |||
| 26dce75391 | |||
| fd26731f53 | |||
| e5756ca1e0 | |||
| 34fc1d2aec | |||
| 1e12ebe97f | |||
| dde546460d | |||
| eb454ac214 | |||
| c41df0cb9a | |||
| 3e2185aea7 | |||
| b700559a4e | |||
| 240d5c0842 | |||
| 07805a4645 | |||
| 802e33dfc8 | |||
| eec2841a24 | |||
| 20eb4eea7a | |||
| fd1fab4c46 | |||
| 3e5ba48531 | |||
| 7353058e3d | |||
| 21d1a5dae5 | |||
| 5435336b28 | |||
| 6ee38f3e09 | |||
| d2df8fb83e | |||
| 6693fa69d2 | |||
| 5ac87a6bfa | |||
| 700d8245cb | |||
| 683ebee979 | |||
| 9676be21f8 | |||
| a6afc9d2bb | |||
| 97d28c427e | |||
| 3e8ea3f06f | |||
| 6e03995d2b | |||
| c8c213ac38 | |||
| ad637adc0d | |||
| 9b543ae650 | |||
| fca1f956f0 | |||
| 448705b338 | |||
| 1b144e932e | |||
| 91d8d22b3e | |||
| 04950cd7bd | |||
| 7097ca2b49 | |||
| d8a900d19b | |||
| 7d628b0df3 | |||
| fc11d7f742 | |||
| 2873226d5a | |||
| f64865f02d | |||
| 84e14cfa24 | |||
| 0c446a4f26 | |||
| 6c80fb6597 | |||
| 59974ea689 | |||
| d02ec080f0 | |||
| 5f6824cc21 | |||
| 5ef9a45125 | |||
| 1c3bb301a5 | |||
| 73bfb11c3e | |||
| ce10ea457f | |||
| 6e6743c58a | |||
| 7695a63157 | |||
| 177dade8f5 | |||
| a87e741eba | |||
| 215dbfc2e0 | |||
| 569add8750 | |||
| 45e9b2361a | |||
| 9aa437c71f | |||
| 1b22251287 | |||
| 30f1979f73 | |||
| c8eae42842 | |||
| d1738addf8 | |||
| 3c81eaa0ac | |||
| c1f99d9919 | |||
| c8d2acc8cd | |||
| 10d0957229 | |||
| 1db6a8d36b | |||
| 26ee0db93b | |||
| 368291f3c1 | |||
| af208eb863 | |||
| 4f7685c9d1 | |||
| 7de3ac08ca | |||
| 9515e12615 | |||
| e1f27963af | |||
| 44e3fb90db | |||
| 0a6b7158f2 | |||
| ecfe99e00b | |||
| 7203c21033 | |||
| 827af033de | |||
| cd8279cd8c | |||
| d0a05da0c8 | |||
| 9fb1716ceb | |||
| ae5e76d11f | |||
| 4f0bc4ee1c | |||
| 84104e7415 | |||
| 81dc407534 | |||
| 2e3dfc44a9 | |||
| d89333df1f | |||
| 38d8c64eb3 | |||
| a7097b0e08 | |||
| e75f7e3d06 | |||
| b54432e49c | |||
| f913942884 | |||
| 993411ece6 | |||
| e8cc5bc2e0 | |||
| 9466cfb60a | |||
| 6357374424 | |||
| 0a2792614c | |||
| d2c16a05bc | |||
| fcf6a5e397 | |||
| 1dfb9b5b42 | |||
| 50338e4c8b | |||
| ea9c29ec48 | |||
| 1e33ae6ecf | |||
| f0523e4a99 | |||
| e179430bce | |||
| a2e38048be | |||
| c50a0a9b27 | |||
| d141330353 | |||
| b6378a5559 | |||
| 5ebb541f8e | |||
| 0a8a3fde10 | |||
| 6b29d970f2 | |||
| caf97ba94e | |||
| 832f3f157a | |||
| 9fee09aa0f | |||
| 0ecfd13b95 | |||
| 80ed412f2c | |||
| 979931c880 | |||
| 8490feb378 | |||
| 16829738f0 | |||
| 0ec5ceba16 | |||
| 00aa8475ff | |||
| e19fa45bbe | |||
| 5858805023 | |||
| 2a9d16e130 | |||
| 3c03de593f | |||
| 58c637bfde | |||
| 87ec0e2f9a | |||
| be798e597e | |||
| 9f25b942f3 | |||
| a16a4a650d | |||
| 5106596545 | |||
| 953dc09b57 | |||
| a8c653ebfd | |||
| 28e5c8cc3c | |||
| c1ccd11e42 | |||
| 386556ad7a | |||
| 83abc2cb18 | |||
| 627aa7d3f0 | |||
| 09c6ab0945 | |||
| 9520a4e0cd | |||
| 58e38ace1e | |||
| 14fe238815 | |||
| 2f368822bc | |||
| ea5f0819c5 | |||
| 8a82d2d5ab | |||
| e2c7d37fe6 | |||
| a6182fef59 | |||
| a94e0a7ea6 | |||
| ed4a6054d8 | |||
| 09242f526d | |||
| 0cb77eaa44 | |||
| 7bbb5b2868 | |||
| 3d28c41d1c | |||
| 9c6719055e | |||
| 2d5ba6312f | |||
| dd91a7329e | |||
| b207c2ce9c | |||
| 8ef6b3dfde | |||
| 6b62b82e1a | |||
| 3b040fe7c1 | |||
| 3991c2aa73 | |||
| 3e1cb2c6fa | |||
| e378c2d267 | |||
| a26a7d8191 | |||
| 23f8661f4e | |||
| 623eede63e | |||
| c97f36fa83 | |||
| 12acc19c37 | |||
| 2f4ebbbbe9 | |||
| 9dfbd92b40 | |||
| e1dd6a9dff | |||
| 3b7b986954 | |||
| d086bfff83 | |||
| 2957ddac72 | |||
| 055bcbf797 | |||
| 7f1ac84759 | |||
| 25e258c360 | |||
| 3efb5d271f | |||
| f02f0dd54b | |||
| b0e79a919c | |||
| b8672ce0f2 | |||
| 5c173daddc | |||
| d1341457f1 | |||
| d30a6ec102 | |||
| 8b40776d15 | |||
| 1bd534f39d | |||
| 52c94ca47d | |||
| 3cb16d3813 | |||
| 724331c579 | |||
| b31db2fc7e | |||
| cfba6e3fe6 | |||
| 98a2c004ab | |||
| 592da77779 | |||
| d6e92fbf6c | |||
| c4313d89d1 | |||
| a54abe3f65 | |||
| 523f5b70b1 | |||
| 96797d5da1 | |||
| 35e11996f9 | |||
| 2d8e953343 | |||
| 636ab0a6c4 | |||
| cfc284beb6 | |||
| 465c2714be | |||
| 7fab3c1652 | |||
| 7b4c4016d3 | |||
| fe7827697e | |||
| 5f34186b4f | |||
| 514d965912 | |||
| 431bb0e5e3 | |||
| bd4992e70f | |||
| 640ff09de4 | |||
| 6cbe04160d | |||
| f189ab2733 | |||
| d1bb999f84 | |||
| 2f322f74a4 | |||
| 3dd0d555d3 | |||
| a587f63dfc | |||
| 84ec638d5c | |||
| fd26919f2e | |||
| cd5db3dc55 | |||
| d746073c3b | |||
| 858051bf2c | |||
| dccf3358c4 | |||
| 93333921c2 | |||
| 38af36b139 | |||
| e1b30a229e | |||
| e0972b3bd3 | |||
| c48c1abdc6 | |||
| 4f56c48b61 | |||
| b94e285a37 | |||
| c99770cf05 | |||
| 053e07cf5a | |||
| 6ebc88dc2e | |||
| aa68dca51c | |||
| 06d7aa1874 | |||
| 3d611684e4 | |||
| 484ffd482b | |||
| 4c2b9cc816 | |||
| 9c281c2db1 | |||
| c68210be47 | |||
| 55344e88d5 | |||
| 368aaaea8b | |||
| d4cbe72c98 | |||
| 5865cbb75b | |||
| 5f81b77081 | |||
| 6f77caca4f | |||
| d469565038 | |||
| 5146ad8b13 | |||
| 63fbbb2125 | |||
| 92b7fa8c77 | |||
| 0e60bf36c5 | |||
| d297d10b3c | |||
| b547701ef9 | |||
| 53f685283e | |||
| 76fa2a9a47 | |||
| adc3ddb68e | |||
| 2bb2c9f343 | |||
| b7485ed56c | |||
| cf459bd402 | |||
| 8cab366214 | |||
| 23e6365778 | |||
| 8b8c83f061 | |||
| ce3b5b9a77 | |||
| 81d81299bd | |||
| 93b7c87b95 | |||
| 259eac73d3 | |||
| fb04784af2 | |||
| c2d97f1165 | |||
| e72552b2cd | |||
| 4cb75e3962 | |||
| e435456e03 | |||
| 0ffb4a5509 | |||
| 7fe9149dbf | |||
| 61815dcd50 | |||
| 56d6a583f0 | |||
| 4a54c24244 | |||
| b2793c943d | |||
| 8c230bf21d | |||
| f7a5b07d53 | |||
| 730fc04382 | |||
| bc0dd36aec | |||
| f2964c7281 | |||
| cf464951be | |||
| 14f860bb8e | |||
| 02adcee6f2 | |||
| fd7505160d | |||
| 808f17c380 | |||
| 6e3512ff0e | |||
| 2475ef7675 | |||
| d020ce65bb | |||
| 9dfa9aa010 | |||
| dc177b0cb5 | |||
| e6b10e1b9a | |||
| 0a72677904 | |||
| 9c6d2df54d | |||
| 5198eea6a8 | |||
| bf07717bcd | |||
| 781ccd3347 | |||
| 6b20e81005 | |||
| e82302327e | |||
| d2665a1bab | |||
| 529b4c7f3b | |||
| 0d00a56e02 | |||
| 058e7b6336 | |||
| d89ed6b36e | |||
| 5d603e1316 | |||
| 5dc01dbae8 | |||
| 2ff97a3c6c | |||
| d17e5e49d8 | |||
| ed0c759578 | |||
| 776d30ea75 | |||
| 76b4475187 | |||
| 06083b7564 | |||
| 7b61d013d9 | |||
| 188b7fa96d | |||
| 2915cb333f | |||
| f74340c85e | |||
| 9a4d0ad460 | |||
| 7bf7fb2669 | |||
| 00943011d9 | |||
| e381dc357a | |||
| 031a65bdc1 | |||
| 9efe715a4b | |||
| 6bbafa679f | |||
| 4c879b4d5d | |||
| fb52c697f2 | |||
| f226b0540e | |||
| be2cf0c768 | |||
| 0be22f94c3 | |||
| 555a8e9ce6 | |||
| 6e562ac9ab | |||
| 4283504248 | |||
| 3146acf819 | |||
| 8688f2d5c1 | |||
| 56c08aa702 | |||
| eda31a964a | |||
| 8b7cc57256 | |||
| 351d894493 | |||
| 1584b8b0e2 | |||
| b845e0f4f4 | |||
| cea42985ac | |||
| 6b19f7ffe6 | |||
| 97ef425d73 | |||
| 6bf15574d0 | |||
| 3cb849cb01 | |||
| dde9b22a8e | |||
| 5ebd15afc6 | |||
| c7a2280e36 | |||
| 3de82418a6 | |||
| a3143e85cf | |||
| 3c23363139 | |||
| 44e57d426c | |||
| b876879204 | |||
| 8e2d02296b | |||
| fb3078e4c8 | |||
| 0994a359d5 | |||
| 1ec058b7a1 | |||
| 163b496f8b | |||
| f2e9d495b0 | |||
| a03048d875 | |||
| 337f510212 | |||
| f001d79eaa | |||
| cf5f2acba3 | |||
| b394bdd9f0 | |||
| b632c0b5e4 | |||
| 978e44aa36 | |||
| c4be498953 | |||
| c5a43c32e1 | |||
| 8c45f6b081 | |||
| a5c87b6a6b | |||
| 45a41642bb | |||
| cb3b499674 | |||
| ec8e002276 | |||
| 1b2b73eb6a | |||
| e30ac4daac | |||
| 195dc25ad5 | |||
| c284255d3b | |||
| bee3104844 | |||
| 241c954d31 | |||
| 0eb446ecb2 | |||
| bd1e9e7da1 | |||
| 0be2363ca1 | |||
| 74b3e27aa8 | |||
| df886f22da | |||
| a688da0051 | |||
| 4a45167436 | |||
| 0928ae2f74 | |||
| 28c84c0297 | |||
| 09a74e37ce | |||
| 3821430d17 | |||
| 3df3b9e987 | |||
| a91a6303b8 | |||
| 209f2a4450 | |||
| 92fa2639a8 | |||
| 5505db6539 | |||
| 51e8c081a1 | |||
| 00dc4f2d3d | |||
| 24a1539a9c | |||
| 4cc620671e | |||
| aa1f74b81b | |||
| 2de20cdfbc | |||
| 232435c0c0 |
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"inputs": ["./package.json"],
|
||||||
|
"output": "./THIRD-PARTY",
|
||||||
|
"overwrite": true,
|
||||||
|
"ci": true
|
||||||
|
}
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
*Issue #, if available:*
|
_Issue #, if available:_
|
||||||
|
|
||||||
*Description of changes:*
|
_Description of changes:_
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
* [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws-actions/configure-aws-credentials/blob/main/CONTRIBUTING.md)
|
- [ ] Have you followed the guidelines in our
|
||||||
|
[Contributing guide?](https://github.com/aws-actions/configure-aws-credentials/blob/main/CONTRIBUTING.md)
|
||||||
|
|
||||||
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
|
By submitting this pull request, I confirm that you can use, modify, copy, and
|
||||||
|
redistribute this contribution, under the terms of your choice.
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
name: "CodeQL config"
|
||||||
|
|
||||||
|
paths-ignore:
|
||||||
|
- dist
|
||||||
|
- node_modules
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
Port 9999
|
||||||
|
Listen 127.0.0.1
|
||||||
|
Timeout 600
|
||||||
|
Allow 127.0.0.1
|
||||||
|
LogFile "/home/runner/work/configure-aws-credentials/configure-aws-credentials/integ_proxy_log.txt"
|
||||||
|
LogLevel Connect
|
||||||
@@ -13,7 +13,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Configure AWS credentials
|
- name: Configure AWS credentials
|
||||||
uses: aws-actions/configure-aws-credentials@v4
|
uses: aws-actions/configure-aws-credentials@v6
|
||||||
with:
|
with:
|
||||||
aws-region: us-west-2
|
aws-region: us-west-2
|
||||||
role-to-assume: ${{ secrets.SECRETS_AWS_PACKAGING_ROLE_TO_ASSUME }}
|
role-to-assume: ${{ secrets.SECRETS_AWS_PACKAGING_ROLE_TO_ASSUME }}
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ jobs:
|
|||||||
- name: Get Metadata
|
- name: Get Metadata
|
||||||
id: dependabot-metadata
|
id: dependabot-metadata
|
||||||
uses: dependabot/fetch-metadata@v2
|
uses: dependabot/fetch-metadata@v2
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
name: Clone repo
|
name: Clone repo
|
||||||
- name: Configure AWS credentials
|
- name: Configure AWS credentials
|
||||||
uses: aws-actions/configure-aws-credentials@v4
|
uses: aws-actions/configure-aws-credentials@v6
|
||||||
with:
|
with:
|
||||||
aws-region: us-west-2
|
aws-region: us-west-2
|
||||||
role-to-assume: ${{ secrets.CONFIGUREAWSCREDENTIALSPACKAGEROLEARN }}
|
role-to-assume: ${{ secrets.CONFIGUREAWSCREDENTIALSPACKAGEROLEARN }}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ jobs:
|
|||||||
contents: read
|
contents: read
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
ref: ${{ github.ref_name }}
|
ref: ${{ github.ref_name }}
|
||||||
@@ -28,7 +28,7 @@ jobs:
|
|||||||
npm test
|
npm test
|
||||||
npm run package
|
npm run package
|
||||||
- name: Configure AWS credentials
|
- name: Configure AWS credentials
|
||||||
uses: aws-actions/configure-aws-credentials@v4
|
uses: aws-actions/configure-aws-credentials@v6
|
||||||
with:
|
with:
|
||||||
aws-region: us-west-2
|
aws-region: us-west-2
|
||||||
role-to-assume: ${{ secrets.SECRETS_AWS_PACKAGING_ROLE_TO_ASSUME }}
|
role-to-assume: ${{ secrets.SECRETS_AWS_PACKAGING_ROLE_TO_ASSUME }}
|
||||||
@@ -47,5 +47,6 @@ jobs:
|
|||||||
git config user.email "github-aws-sdk-osds-automation@amazon.com"
|
git config user.email "github-aws-sdk-osds-automation@amazon.com"
|
||||||
git remote set-url origin https://${{ env.OSDS_ACCESS_TOKEN }}@github.com/aws-actions/configure-aws-credentials.git
|
git remote set-url origin https://${{ env.OSDS_ACCESS_TOKEN }}@github.com/aws-actions/configure-aws-credentials.git
|
||||||
git add dist
|
git add dist
|
||||||
|
git add THIRD-PARTY
|
||||||
git commit -m "chore: Update dist" || echo "No changes to commit"
|
git commit -m "chore: Update dist" || echo "No changes to commit"
|
||||||
git push --force origin
|
git push --force origin
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
id-token: write
|
id-token: write
|
||||||
@@ -15,12 +16,12 @@
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Repository
|
- name: Checkout Repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Configure AWS Credentials
|
- name: Configure AWS Credentials
|
||||||
uses: aws-actions/configure-aws-credentials@v4
|
uses: aws-actions/configure-aws-credentials@v6
|
||||||
with:
|
with:
|
||||||
aws-region: us-west-2
|
aws-region: us-west-2
|
||||||
role-to-assume: ${{ secrets.SECRETS_AWS_PACKAGING_ROLE_TO_ASSUME }}
|
role-to-assume: ${{ secrets.SECRETS_AWS_PACKAGING_ROLE_TO_ASSUME }}
|
||||||
@@ -35,9 +36,41 @@
|
|||||||
${{ secrets.OSDS_PACKAGING_ROLE }}
|
${{ secrets.OSDS_PACKAGING_ROLE }}
|
||||||
|
|
||||||
- name: Run release-please
|
- name: Run release-please
|
||||||
|
id: release
|
||||||
uses: googleapis/release-please-action@v4
|
uses: googleapis/release-please-action@v4
|
||||||
with:
|
with:
|
||||||
release-type: node
|
release-type: node
|
||||||
token: ${{ env.OSDS_ACCESS_TOKEN }}
|
token: ${{ env.OSDS_ACCESS_TOKEN }}
|
||||||
config-file: release-please-config.json
|
config-file: release-please-config.json
|
||||||
manifest-file: .release-please-manifest.json
|
manifest-file: .release-please-manifest.json
|
||||||
|
|
||||||
|
- name: Checkout Again
|
||||||
|
uses: actions/checkout@v5
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Tag Major Version
|
||||||
|
if: ${{ steps.release.outputs.release_created }}
|
||||||
|
run: |
|
||||||
|
git config user.name "GitHub Actions"
|
||||||
|
git config user.email "github-aws-sdk-osds-automation@amazon.com"
|
||||||
|
if git rev-parse "v${{ steps.release.outputs.major }}" >/dev/null 2>&1; then
|
||||||
|
git tag -d "v${{ steps.release.outputs.major }}"
|
||||||
|
git push origin ":v${{ steps.release.outputs.major }}"
|
||||||
|
fi
|
||||||
|
git tag -a "v${{ steps.release.outputs.major }}" -m "Release v${{ steps.release.outputs.major }}"
|
||||||
|
git push origin "v${{ steps.release.outputs.major }}"
|
||||||
|
|
||||||
|
- name: Update README version references
|
||||||
|
if: ${{ steps.release.outputs.release_created }}
|
||||||
|
run: |
|
||||||
|
sed -i 's|configure-aws-credentials@v[0-9]*\.[0-9]*\.[0-9]*|configure-aws-credentials@${{ steps.release.outputs.tag_name }}|g' README.md
|
||||||
|
if git diff --quiet README.md; then
|
||||||
|
echo "README already up to date"
|
||||||
|
else
|
||||||
|
echo "::add-mask::${{ env.OSDS_ACCESS_TOKEN }}"
|
||||||
|
git remote set-url origin https://${{ env.OSDS_ACCESS_TOKEN }}@github.com/aws-actions/configure-aws-credentials.git
|
||||||
|
git add README.md
|
||||||
|
git commit -m "docs: update README version references to ${{ steps.release.outputs.tag_name }}"
|
||||||
|
git push --force origin
|
||||||
|
fi
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
name: Run post-release integration test
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
paths:
|
||||||
|
- 'dist/**'
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
package_and_test:
|
||||||
|
name: Package dist files
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
id-token: write
|
||||||
|
contents: read
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v5
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Integation tests
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
aws-region: us-west-2
|
||||||
|
role-to-assume: ${{ secrets.CAWSC_integ_role }}
|
||||||
|
role-session-name: IntegTestCAWSC
|
||||||
|
- name: Get caller identity
|
||||||
|
run: |
|
||||||
|
aws sts get-caller-identity
|
||||||
@@ -0,0 +1,281 @@
|
|||||||
|
name: Run pre-release integ tests
|
||||||
|
on:
|
||||||
|
pull_request_target:
|
||||||
|
workflow_dispatch:
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
oidc:
|
||||||
|
if: ${{ github.event_name == 'workflow_dispatch' || (github.event.pull_request.user.login == 'aws-sdk-osds' && github.repository == 'aws-actions/configure-aws-credentials') }}
|
||||||
|
permissions:
|
||||||
|
id-token: write
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [windows-latest, ubuntu-latest, macos-latest]
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
name: OIDC login test
|
||||||
|
steps:
|
||||||
|
- name: checkout
|
||||||
|
uses: actions/checkout@v5
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Configure AWS credentials
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
aws-region: us-west-2
|
||||||
|
role-to-assume: ${{ secrets.OIDC_integ_role }}
|
||||||
|
- name: Get Caller Identity
|
||||||
|
run: |
|
||||||
|
aws sts get-caller-identity
|
||||||
|
|
||||||
|
#can cut this test out if it's not necessary
|
||||||
|
static_assumeRole:
|
||||||
|
if: ${{ github.event_name == 'workflow_dispatch' || (github.event.pull_request.user.login == 'aws-sdk-osds' && github.repository == 'aws-actions/configure-aws-credentials') }}
|
||||||
|
permissions:
|
||||||
|
id-token: write
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [windows-latest, ubuntu-latest, macos-latest]
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: bash
|
||||||
|
name: Static IAM creds test
|
||||||
|
steps:
|
||||||
|
- name: checkout
|
||||||
|
uses: actions/checkout@v5
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
persist-credentials: false
|
||||||
|
- name: assume creator Role
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
aws-region: us-west-2
|
||||||
|
role-to-assume: ${{ secrets.STATIC_USER_CREATION_ROLE }}
|
||||||
|
- name: create and mask access key
|
||||||
|
id: create-key
|
||||||
|
run: |
|
||||||
|
AK_OUTPUT=$(aws iam create-access-key --user-name integ-test-static-user-${{ runner.os }})
|
||||||
|
AK_ID=$(echo $AK_OUTPUT | jq -r '.AccessKey.AccessKeyId')
|
||||||
|
SECRET_AK=$(echo $AK_OUTPUT | jq -r '.AccessKey.SecretAccessKey')
|
||||||
|
echo "::add-mask::$AK_ID"
|
||||||
|
echo "::add-mask::$SECRET_AK"
|
||||||
|
echo "STATIC_ACCESS_KEY_ID=$AK_ID" >> $GITHUB_OUTPUT
|
||||||
|
echo "STATIC_SECRET_ACCESS_KEY=$SECRET_AK" >> $GITHUB_OUTPUT
|
||||||
|
- name: sleep so key can propagate
|
||||||
|
run: sleep 30
|
||||||
|
- name: assume role with static creds
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
aws-region: us-west-2
|
||||||
|
role-to-assume: ${{ secrets.STATIC_TEST_TARGET_ROLE }}
|
||||||
|
aws-access-key-id: ${{ steps.create-key.outputs.STATIC_ACCESS_KEY_ID }}
|
||||||
|
aws-secret-access-key: ${{ steps.create-key.outputs.STATIC_SECRET_ACCESS_KEY }}
|
||||||
|
- name: check account
|
||||||
|
run: aws sts get-caller-identity
|
||||||
|
- name: log back into creator role
|
||||||
|
if: success() || failure()
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
aws-region: us-west-2
|
||||||
|
role-to-assume: ${{ secrets.STATIC_USER_CREATION_ROLE }}
|
||||||
|
- name: delete access key
|
||||||
|
if: success() || failure()
|
||||||
|
run: |
|
||||||
|
aws iam delete-access-key --user-name integ-test-static-user-${{ runner.os }} --access-key-id ${{ steps.create-key.outputs.STATIC_ACCESS_KEY_ID }}
|
||||||
|
|
||||||
|
role_chaining:
|
||||||
|
if: ${{ github.event_name == 'workflow_dispatch' || (github.event.pull_request.user.login == 'aws-sdk-osds' && github.repository == 'aws-actions/configure-aws-credentials') }}
|
||||||
|
permissions:
|
||||||
|
id-token: write
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [windows-latest, ubuntu-latest, macos-latest]
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
name: Existing Creds + Role Chaining test
|
||||||
|
steps:
|
||||||
|
- name: checkout
|
||||||
|
uses: actions/checkout@v5
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Configure AWS credentials
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
aws-region: us-west-2
|
||||||
|
role-to-assume: ${{ secrets.ROLE_chaining_1 }}
|
||||||
|
- name: Get Caller Identity
|
||||||
|
run: |
|
||||||
|
aws sts get-caller-identity
|
||||||
|
- name: assume second role
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
aws-region: us-west-2
|
||||||
|
role-to-assume: ${{ secrets.ROLE_chaining_2 }}
|
||||||
|
role-chaining: true
|
||||||
|
- name: get caller identity
|
||||||
|
run: |
|
||||||
|
aws sts get-caller-identity
|
||||||
|
|
||||||
|
inline_policy:
|
||||||
|
if: ${{ github.event_name == 'workflow_dispatch' || (github.event.pull_request.user.login == 'aws-sdk-osds' && github.repository == 'aws-actions/configure-aws-credentials') }}
|
||||||
|
permissions:
|
||||||
|
id-token: write
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, macos-latest]
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
name: Inline Policy Test
|
||||||
|
steps:
|
||||||
|
- name: checkout
|
||||||
|
uses: actions/checkout@v5
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
persist-credentials: false
|
||||||
|
- name: get creds w scoped down policy
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
aws-region: us-west-2
|
||||||
|
role-to-assume: ${{ secrets.INLINE_policy_role }}
|
||||||
|
inline-session-policy: '{"Version":"2012-10-17","Statement":[{"Sid":"Stmt1","Effect":"Allow","Action":"s3:ListAllMyBuckets","Resource":"*"}]}'
|
||||||
|
|
||||||
|
#NOTE: This step should succeed. The role should have permission only to list all buckets.
|
||||||
|
- name: list buckets
|
||||||
|
run: aws s3 ls > /dev/null
|
||||||
|
|
||||||
|
#NOTE: This step should fail. we don't want the role to have permission to see the bucket contents.
|
||||||
|
- name: try to list bucket contents
|
||||||
|
id: bucketContentsStep
|
||||||
|
continue-on-error: true
|
||||||
|
run: aws s3 ls s3://cawsc-integ-tests-bucket > /dev/null
|
||||||
|
|
||||||
|
#But the test fails if we could list the bucket contents.
|
||||||
|
- name: fail if we can list bucket contents
|
||||||
|
if: steps.bucketContentsStep.outcome == 'success'
|
||||||
|
run: exit 1
|
||||||
|
|
||||||
|
http-proxy:
|
||||||
|
if: ${{ github.event_name == 'workflow_dispatch' || (github.event.pull_request.user.login == 'aws-sdk-osds' && github.repository == 'aws-actions/configure-aws-credentials') }}
|
||||||
|
permissions:
|
||||||
|
id-token: write
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
name: HTTP Proxy Test
|
||||||
|
steps:
|
||||||
|
- name: checkout
|
||||||
|
uses: actions/checkout@v5
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
persist-credentials: false
|
||||||
|
- name: install tinyproxy
|
||||||
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get -y install tinyproxy
|
||||||
|
- name: start tinyproxy
|
||||||
|
run: tinyproxy -c .github/integ_tests/tinyproxy.conf
|
||||||
|
- name: Configure AWS credentials
|
||||||
|
continue-on-error: true
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
aws-region: us-west-2
|
||||||
|
role-to-assume: ${{ secrets.OIDC_integ_role }}
|
||||||
|
http-proxy: http://127.0.0.1:9999
|
||||||
|
retry-max-attempts: 4
|
||||||
|
- name: checkout logs
|
||||||
|
run: cat integ_proxy_log.txt
|
||||||
|
- name: check logs to see if successful call
|
||||||
|
run: grep -q "Request" integ_proxy_log.txt && echo "PROXY_CALL_LOGGED=1" >> $GITHUB_ENV || echo "PROXY_CALL_LOGGED=0" >> $GITHUB_ENV
|
||||||
|
- name: fail job if bad call
|
||||||
|
if: ${{ env.PROXY_CALL_LOGGED != 1 }}
|
||||||
|
run: exit 1
|
||||||
|
|
||||||
|
token-file:
|
||||||
|
if: ${{ github.event_name == 'workflow_dispatch' || (github.event.pull_request.user.login == 'aws-sdk-osds' && github.repository == 'aws-actions/configure-aws-credentials') }}
|
||||||
|
permissions:
|
||||||
|
id-token: write
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [windows-latest, ubuntu-latest, macos-latest]
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
name: Token File Test
|
||||||
|
steps:
|
||||||
|
- name: checkout
|
||||||
|
uses: actions/checkout@v5
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
persist-credentials: false
|
||||||
|
- name: fetch token and write to file
|
||||||
|
uses: actions/github-script@v8
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
const fs = require('fs');
|
||||||
|
async function getIDTokenAction() {
|
||||||
|
const id_token = await core.getIDToken("sts.amazonaws.com");
|
||||||
|
return id_token;
|
||||||
|
}
|
||||||
|
const idToken = await getIDTokenAction();
|
||||||
|
fs.writeFileSync(".github/integ_tests/integ_token.txt", idToken, (err) => {
|
||||||
|
if (err) throw err;
|
||||||
|
});
|
||||||
|
- name: get creds with that file
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
aws-region: us-west-2
|
||||||
|
role-to-assume: ${{ secrets.OIDC_integ_role }}
|
||||||
|
web-identity-token-file: .github/integ_tests/integ_token.txt
|
||||||
|
retry-max-attempts: 4
|
||||||
|
- name: check creds
|
||||||
|
run: aws sts get-caller-identity
|
||||||
|
|
||||||
|
profile-oidc:
|
||||||
|
if: ${{ github.event_name == 'workflow_dispatch' || (github.event.pull_request.user.login == 'aws-sdk-osds' && github.repository == 'aws-actions/configure-aws-credentials') }}
|
||||||
|
permissions:
|
||||||
|
id-token: write
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [windows-latest, ubuntu-latest, macos-latest]
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
name: OIDC profile writing test
|
||||||
|
steps:
|
||||||
|
- name: checkout
|
||||||
|
uses: actions/checkout@v5
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: make profile 1
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
aws-region: us-east-1
|
||||||
|
role-to-assume: ${{ secrets.INTEG_PROFILE_ROLE_1 }}
|
||||||
|
aws-profile: TestProfile1
|
||||||
|
|
||||||
|
- name: make profile 2
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
aws-region: us-east-2
|
||||||
|
role-to-assume: ${{ secrets.INTEG_PROFILE_ROLE_2 }}
|
||||||
|
aws-profile: TestProfile2
|
||||||
|
|
||||||
|
- name: check profile1
|
||||||
|
run: aws sts get-caller-identity --profile TestProfile1
|
||||||
|
|
||||||
|
- name: check profile2
|
||||||
|
run: aws sts get-caller-identity --profile TestProfile2
|
||||||
|
|
||||||
|
- name: Get Caller Identity
|
||||||
|
id: no-creds-sts-step
|
||||||
|
continue-on-error: true
|
||||||
|
run: |
|
||||||
|
aws sts get-caller-identity
|
||||||
|
|
||||||
|
- name: fail if we got caller id with env creds
|
||||||
|
if: steps.no-creds-sts-step.outcome == 'success'
|
||||||
|
run: exit 1
|
||||||
@@ -2,6 +2,8 @@ on:
|
|||||||
[pull_request]
|
[pull_request]
|
||||||
|
|
||||||
name: Run unit tests
|
name: Run unit tests
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
unit-test:
|
unit-test:
|
||||||
@@ -14,13 +16,13 @@ jobs:
|
|||||||
timeout-minutes: 5
|
timeout-minutes: 5
|
||||||
steps:
|
steps:
|
||||||
- name: "Checkout repository"
|
- name: "Checkout repository"
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
- name: "Setup node"
|
- name: "Setup node"
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v6.4.0
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
node-version: 24
|
||||||
- name: "Install dependencies"
|
- name: "Install dependencies"
|
||||||
uses: bahmutov/npm-install@v1
|
run: npm ci
|
||||||
- name: "Run tests"
|
- name: "Run tests"
|
||||||
run: npm run test --if-present
|
run: npm run test --if-present
|
||||||
lint:
|
lint:
|
||||||
@@ -29,7 +31,7 @@ jobs:
|
|||||||
timeout-minutes: 5
|
timeout-minutes: 5
|
||||||
steps:
|
steps:
|
||||||
- name: "Checkout repostiory"
|
- name: "Checkout repostiory"
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
- name: "Setup node"
|
- name: "Setup node"
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
.history
|
||||||
node_modules
|
node_modules
|
||||||
coverage
|
coverage
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
default: true
|
||||||
|
MD007:
|
||||||
|
indent: 4
|
||||||
|
heading-style:
|
||||||
|
style: atx
|
||||||
|
ul-style:
|
||||||
|
style: dash
|
||||||
|
line-length:
|
||||||
|
stern: true
|
||||||
|
tables: false
|
||||||
|
code_blocks: false
|
||||||
|
no-inline-html:
|
||||||
|
allowed_elements:
|
||||||
|
- details
|
||||||
|
- summary
|
||||||
|
code-block-style:
|
||||||
|
style: fenced
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
".release-please-manifest.json": "4.0.2",
|
".release-please-manifest.json": "4.0.2",
|
||||||
"package.json": "4.0.2",
|
"package.json": "6.0.0",
|
||||||
".": "4.3.1"
|
".": "6.2.0"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,98 @@
|
|||||||
|
|
||||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||||
|
|
||||||
|
## [6.2.0](https://github.com/aws-actions/configure-aws-credentials/compare/v6.1.3...v6.2.0) (2026-06-01)
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add additional session tags by default ([#1775](https://github.com/aws-actions/configure-aws-credentials/issues/1775)) ([e0ba768](https://github.com/aws-actions/configure-aws-credentials/commit/e0ba7685077379a14a82d01fefd511490344ebfc))
|
||||||
|
* add more retry logic and better logging ([#1764](https://github.com/aws-actions/configure-aws-credentials/issues/1764)) ([540d0c1](https://github.com/aws-actions/configure-aws-credentials/commit/540d0c13aedb8d55501d220bd2f0b3cdedfe84e8))
|
||||||
|
* add regex validation to role-session-name ([#1765](https://github.com/aws-actions/configure-aws-credentials/issues/1765)) ([e354499](https://github.com/aws-actions/configure-aws-credentials/commit/e35449909c6ede5083a48ba4b8bbfaaa1cf09ba1))
|
||||||
|
* Allow custom session tags to be passed when assuming a role ([#1759](https://github.com/aws-actions/configure-aws-credentials/issues/1759)) ([61f50f6](https://github.com/aws-actions/configure-aws-credentials/commit/61f50f630f383628add73c1eab3f1935ba07da2b))
|
||||||
|
* expose run id in STS client user-agent ([#1774](https://github.com/aws-actions/configure-aws-credentials/issues/1774)) ([29d1be3](https://github.com/aws-actions/configure-aws-credentials/commit/29d1be30273e7ef371d59fccf6ec54572c64ec89))
|
||||||
|
* support custom STS endpoints ([#1762](https://github.com/aws-actions/configure-aws-credentials/issues/1762)) ([8d52d05](https://github.com/aws-actions/configure-aws-credentials/commit/8d52d05d7a4521fa52b39de50cb6114b12e5c332))
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* skip credential check on output-env-credentials: false ([#1778](https://github.com/aws-actions/configure-aws-credentials/issues/1778)) ([58e7c47](https://github.com/aws-actions/configure-aws-credentials/commit/58e7c47adf77846879008deadfeeef8a6969fe6c))
|
||||||
|
* assumeRole failing from session tag size too large ([#1808](https://github.com/aws-actions/configure-aws-credentials/issues/1808)) ([d6f5dc3](https://github.com/aws-actions/configure-aws-credentials/commit/d6f5dc331b44474b19a52caaf85fa4d637b13c8e))
|
||||||
|
|
||||||
|
## [6.1.3](https://github.com/aws-actions/configure-aws-credentials/compare/v6.1.2...v6.1.3) (2026-05-28)
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* fix: allow kubelet token symlink in [#1805](https://github.com/aws-actions/configure-aws-credentials/issues/1805)
|
||||||
|
|
||||||
|
## [6.1.2](https://github.com/aws-actions/configure-aws-credentials/compare/v6.1.1...v6.1.2) (2026-05-26)
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* additional filesystem checks ([#1799](https://github.com/aws-actions/configure-aws-credentials/issues/1799)) ([c39f282](https://github.com/aws-actions/configure-aws-credentials/commit/c39f282697aca8a78c522ecf1f7da9899a31432c))
|
||||||
|
|
||||||
|
## [6.1.1](https://github.com/aws-actions/configure-aws-credentials/compare/v6.1.0...v6.1.1) (2026-05-05)
|
||||||
|
|
||||||
|
|
||||||
|
### Miscellaneous Chores
|
||||||
|
|
||||||
|
* various dependency updates
|
||||||
|
|
||||||
|
## [6.1.0](https://github.com/aws-actions/configure-aws-credentials/compare/v6.0.0...v6.1.0) (2026-04-06)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add skip cleanup option ([#1716](https://github.com/aws-actions/configure-aws-credentials/issues/1716)) ([11b1c58](https://github.com/aws-actions/configure-aws-credentials/commit/11b1c58b24724e66aa52a847862a0c1b0c4b0c7b)), closes [#1545](https://github.com/aws-actions/configure-aws-credentials/issues/1545)
|
||||||
|
* Support usage of AWS Profiles ([#1696](https://github.com/aws-actions/configure-aws-credentials/issues/1696)) ([a7f0c82](https://github.com/aws-actions/configure-aws-credentials/commit/a7f0c828ac76e0d049e34c920172c60f579f9eb3))
|
||||||
|
|
||||||
|
## [6.0.0](https://github.com/aws-actions/configure-aws-credentials/compare/v5.1.1...v6.0.0) (2026-02-04)
|
||||||
|
|
||||||
|
|
||||||
|
### ⚠ BREAKING CHANGES
|
||||||
|
|
||||||
|
* Update action to use node24 ([#1632](https://github.com/aws-actions/configure-aws-credentials/pull/1632)) ([a7a2c11](https://github.com/aws-actions/configure-aws-credentials/commit/a7a2c1125c67f40a1e95768f4e4a7d8f019f87af))
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add support to define transitive tag keys ([#1316](https://github.com/aws-actions/configure-aws-credentials/pull/1316)) ([232435c](https://github.com/aws-actions/configure-aws-credentials/commit/232435c0c05e51137544f0203931b84893d13b74)) ([930ebd9](https://github.com/aws-actions/configure-aws-credentials/pull/1628/changes/930ebd9bcaed959c3ba9e21567e8abbc3cae72c0))
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* properly output `aws-account-id` and `authenticated-arn` when using role-chaining ([#1633](https://github.com/aws-actions/configure-aws-credentials/pull/1633)) ([7ceaf96](https://github.com/aws-actions/configure-aws-credentials/commit/7ceaf96edc86cc1713cef59eba79feeb23f59da1))
|
||||||
|
|
||||||
|
## [5.1.1](https://github.com/aws-actions/configure-aws-credentials/compare/v5.1.0...v5.1.1) (2025-11-24)
|
||||||
|
|
||||||
|
|
||||||
|
### Miscellaneous Chores
|
||||||
|
|
||||||
|
* release 5.1.1 ([56d6a58](https://github.com/aws-actions/configure-aws-credentials/commit/56d6a583f00f6bad6d19d91d53a7bc3b8143d0e9))
|
||||||
|
|
||||||
|
## [5.1.0](https://github.com/aws-actions/configure-aws-credentials/compare/v5.0.0...v5.1.0) (2025-10-06)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* Add global timeout support ([#1487](https://github.com/aws-actions/configure-aws-credentials/issues/1487)) ([1584b8b](https://github.com/aws-actions/configure-aws-credentials/commit/1584b8b0e2062557287c28fbe9b8920df434e866))
|
||||||
|
* add no-proxy support ([#1482](https://github.com/aws-actions/configure-aws-credentials/issues/1482)) ([dde9b22](https://github.com/aws-actions/configure-aws-credentials/commit/dde9b22a8e889a0821997a21a2c5a38020ee8de3))
|
||||||
|
* Improve debug logging in retry logic ([#1485](https://github.com/aws-actions/configure-aws-credentials/issues/1485)) ([97ef425](https://github.com/aws-actions/configure-aws-credentials/commit/97ef425d73aa532439f54f90d0e83101a186c5a6))
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* properly expose getProxyForUrl (introduced in [#1482](https://github.com/aws-actions/configure-aws-credentials/issues/1482)) ([#1486](https://github.com/aws-actions/configure-aws-credentials/issues/1486)) ([cea4298](https://github.com/aws-actions/configure-aws-credentials/commit/cea42985ac88b42678fbc84c18066a7f07f05176))
|
||||||
|
|
||||||
|
## [5.0.0](https://github.com/aws-actions/configure-aws-credentials/compare/v4.3.1...v5.0.0) (2025-09-03)
|
||||||
|
|
||||||
|
|
||||||
|
### ⚠ BREAKING CHANGES
|
||||||
|
|
||||||
|
* Cleanup input handling. Changes invalid boolean input behavior (see #1445)
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add skip OIDC option ([#1458](https://github.com/aws-actions/configure-aws-credentials/issues/1458)) ([8c45f6b](https://github.com/aws-actions/configure-aws-credentials/commit/8c45f6b08196feb86cfdbe431541d5571d9ab2c2))
|
||||||
|
* Cleanup input handling. Changes invalid boolean input behavior (see [#1445](https://github.com/aws-actions/configure-aws-credentials/issues/1445)) ([74b3e27](https://github.com/aws-actions/configure-aws-credentials/commit/74b3e27aa80db064b5bb8c04b22fc607e817acf7))
|
||||||
|
* support account id allowlist ([#1456](https://github.com/aws-actions/configure-aws-credentials/issues/1456)) ([c4be498](https://github.com/aws-actions/configure-aws-credentials/commit/c4be498953fc1da2707a50ce4b761a53af3d02af))
|
||||||
|
|
||||||
## [4.3.1](https://github.com/aws-actions/configure-aws-credentials/compare/v4.3.0...v4.3.1) (2025-08-04)
|
## [4.3.1](https://github.com/aws-actions/configure-aws-credentials/compare/v4.3.0...v4.3.1) (2025-08-04)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+8
-4
@@ -1,4 +1,8 @@
|
|||||||
## Code of Conduct
|
# Code of Conduct
|
||||||
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
|
|
||||||
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
|
This project has adopted the
|
||||||
opensource-codeofconduct@amazon.com with any additional questions or comments.
|
[Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). For
|
||||||
|
more information see the
|
||||||
|
[Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
|
||||||
|
<opensource-codeofconduct@amazon.com> with any additional questions or
|
||||||
|
comments.
|
||||||
|
|||||||
+84
-28
@@ -1,61 +1,117 @@
|
|||||||
# Contributing Guidelines
|
# Contributing Guidelines
|
||||||
|
|
||||||
Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional
|
Thank you for your interest in contributing to our project. Whether it's a bug
|
||||||
documentation, we greatly value feedback and contributions from our community.
|
report, new feature, correction, or additional documentation, we greatly value
|
||||||
|
feedback and contributions from our community.
|
||||||
Please read through this document before submitting any issues or pull requests to ensure we have all the necessary
|
|
||||||
information to effectively respond to your bug report or contribution.
|
|
||||||
|
|
||||||
|
Please read through this document before submitting any issues or pull requests
|
||||||
|
to ensure we have all the necessary information to effectively respond to your
|
||||||
|
bug report or contribution.
|
||||||
|
|
||||||
## Reporting Bugs/Feature Requests
|
## Reporting Bugs/Feature Requests
|
||||||
|
|
||||||
We welcome you to use the GitHub issue tracker to report bugs or suggest features.
|
We welcome you to use the GitHub issue tracker to report bugs or suggest
|
||||||
|
features.
|
||||||
|
|
||||||
When filing an issue, please check [existing open](https://github.com/aws-actions/configure-aws-credentials/issues), or [recently closed](https://github.com/aws-actions/configure-aws-credentials/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), issues to make sure somebody else hasn't already
|
When filing an issue, please check [existing open][open-issues],
|
||||||
reported the issue. Please try to include as much information as you can. Details like these are incredibly useful:
|
or [recently closed][closed-issues], issues to make sure somebody
|
||||||
|
else hasn't already reported the issue.
|
||||||
|
|
||||||
* A reproducible test case or series of steps
|
[open-issues]: https://github.com/aws-actions/configure-aws-credentials/issues
|
||||||
* The version of our code being used
|
[closed-issues]: https://github.com/aws-actions/configure-aws-credentials/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20
|
||||||
* Any modifications you've made relevant to the bug
|
|
||||||
* Anything unusual about your environment or deployment
|
|
||||||
|
|
||||||
|
Please try to include as much information as you can. Details like
|
||||||
|
these are incredibly useful:
|
||||||
|
|
||||||
|
- A reproducible test case or series of steps
|
||||||
|
- The version of our code being used
|
||||||
|
- Any modifications you've made relevant to the bug
|
||||||
|
- Anything unusual about your environment or deployment
|
||||||
|
|
||||||
## Contributing via Pull Requests
|
## Contributing via Pull Requests
|
||||||
Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that:
|
|
||||||
|
|
||||||
1. You are working against the latest source on the *main* branch.
|
Contributions via pull requests are much appreciated. Before sending us a pull
|
||||||
2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already.
|
request, please ensure that:
|
||||||
3. You open an issue to discuss any significant work - we would hate for your time to be wasted.
|
|
||||||
|
1. You are working against the latest source on the _main_ branch.
|
||||||
|
2. You check existing open, and recently merged, pull requests to make sure
|
||||||
|
someone else hasn't addressed the problem already.
|
||||||
|
3. You open an issue to discuss any significant work - we would hate for your
|
||||||
|
time to be wasted.
|
||||||
|
|
||||||
To send us a pull request, please:
|
To send us a pull request, please:
|
||||||
|
|
||||||
1. Fork the repository.
|
1. Fork the repository.
|
||||||
2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change.
|
2. Modify the source; please focus on the specific change you are contributing.
|
||||||
|
If you also reformat all the code, it will be hard for us to focus on your
|
||||||
|
change.
|
||||||
3. Ensure local tests pass.
|
3. Ensure local tests pass.
|
||||||
4. Commit to your fork using clear commit messages.
|
4. Commit to your fork using clear commit messages.
|
||||||
5. Send us a pull request, answering any default questions in the pull request interface.
|
5. Send us a pull request, answering any default questions in the pull request
|
||||||
6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation.
|
interface.
|
||||||
|
6. Pay attention to any automated CI failures reported in the pull request, and
|
||||||
|
stay involved in the conversation.
|
||||||
|
|
||||||
GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and
|
GitHub provides additional document on
|
||||||
[creating a pull request](https://help.github.com/articles/creating-a-pull-request/).
|
[forking a repository](https://help.github.com/articles/fork-a-repo/) and
|
||||||
|
[creating a pull request][create-pr].
|
||||||
|
|
||||||
|
[create-pr]:
|
||||||
|
https://help.github.com/articles/creating-a-pull-request/
|
||||||
|
|
||||||
## Finding contributions to work on
|
## Finding contributions to work on
|
||||||
Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any ['help wanted'](https://github.com/aws-actions/configure-aws-credentials/labels/help%20wanted) issues is a great place to start.
|
|
||||||
|
|
||||||
|
Looking at the existing issues is a great way to find something to contribute
|
||||||
|
on. As our projects, by default, use the default GitHub issue labels
|
||||||
|
(enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any
|
||||||
|
['help wanted'](https://github.com/aws-actions/configure-aws-credentials/labels/help%20wanted)
|
||||||
|
issues is a great place to start.
|
||||||
|
|
||||||
## Code of Conduct
|
## Code of Conduct
|
||||||
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
|
|
||||||
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
|
|
||||||
opensource-codeofconduct@amazon.com with any additional questions or comments.
|
|
||||||
|
|
||||||
|
This project has adopted the
|
||||||
|
[Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). For
|
||||||
|
more information see the
|
||||||
|
[Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
|
||||||
|
<opensource-codeofconduct@amazon.com> with any additional questions or
|
||||||
|
comments.
|
||||||
|
|
||||||
## Security issue notifications
|
## Security issue notifications
|
||||||
If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue.
|
|
||||||
|
|
||||||
|
If you discover a potential security issue in this project we ask that you
|
||||||
|
notify AWS/Amazon Security via our
|
||||||
|
[vulnerability reporting page][vuln-report].
|
||||||
|
|
||||||
|
[vuln-report]:
|
||||||
|
http://aws.amazon.com/security/vulnerability-reporting/
|
||||||
|
Please do **not** create a public github issue.
|
||||||
|
|
||||||
|
## Automated Tools
|
||||||
|
|
||||||
|
The use of AI tooling for assisted development work is accepted and encouraged
|
||||||
|
in this repository, but due to the volume of submissions we ask that you observe
|
||||||
|
the following rules:
|
||||||
|
|
||||||
|
- All issue and pull request submissions to this repository that are sourced by
|
||||||
|
AI must first be reviewed by a human before submitting to the repository.
|
||||||
|
Items reviewed in this way must include a statement like "generated by AI
|
||||||
|
tools, and reviewed by [person]"
|
||||||
|
- Please ensure that your submissions are actually improvements. While we are
|
||||||
|
grateful for any proposed fixes, even if they are very small, behavior that
|
||||||
|
looks like creating noisy PRs or artificially inflating submission counts
|
||||||
|
is not acceptable.
|
||||||
|
- We may close issues or pull requests, or limit your ability to interact with
|
||||||
|
this repository, for behavior that in our estimation violates these rules or
|
||||||
|
any of the other rules in this repository's
|
||||||
|
[Code of Conduct](CODE_OF_CONDUCT.md).
|
||||||
|
|
||||||
## Licensing
|
## Licensing
|
||||||
|
|
||||||
See the [LICENSE](https://github.com/aws-actions/configure-aws-credentials/blob/main/LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution.
|
See the
|
||||||
|
[LICENSE](https://github.com/aws-actions/configure-aws-credentials/blob/main/LICENSE)
|
||||||
|
file for our project's licensing. We will ask you to confirm the licensing of
|
||||||
|
your contribution.
|
||||||
|
|
||||||
We may ask you to sign a [Contributor License Agreement (CLA)](http://en.wikipedia.org/wiki/Contributor_License_Agreement) for larger changes.
|
We may ask you to sign a
|
||||||
|
[Contributor License Agreement (CLA)](http://en.wikipedia.org/wiki/Contributor_License_Agreement)
|
||||||
|
for larger changes.
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
Configure AWS Credentials
|
# Configure AWS Credentials
|
||||||
=========================
|
|
||||||
Authenticate to AWS in GitHub Actions! Works especially well with [AWS Secrets
|
Authenticate to AWS in GitHub Actions (and others)! Works especially well with
|
||||||
Manager](https://github.com/aws-actions/aws-secretsmanager-get-secrets).
|
[AWS Secrets Manager][secretsmanager].
|
||||||
|
|
||||||
|
[secretsmanager]: https://github.com/aws-actions/aws-secretsmanager-get-secrets
|
||||||
|
|
||||||
|
## Quick Start (OIDC, recommended)
|
||||||
|
|
||||||
Quick Start (OIDC, recommended)
|
|
||||||
-------------------------------
|
|
||||||
1. Create an IAM Identity Provider in your AWS account for GitHub OIDC. (See
|
1. Create an IAM Identity Provider in your AWS account for GitHub OIDC. (See
|
||||||
[OIDC configuration](#oidc-configuration) below for details.)
|
[OIDC configuration](#oidc-configuration-details) below for details.)
|
||||||
2. Create an IAM Role in your AWS account with a trust policy that allows GitHub
|
2. Create an IAM Role in your AWS account with a trust policy that allows GitHub
|
||||||
Actions to assume it:
|
Actions to assume it. (Expand the sections below) <details>
|
||||||
<details>
|
|
||||||
<summary>GitHub OIDC Trust Policy</summary>
|
<summary>GitHub OIDC Trust Policy</summary>
|
||||||
|
|
||||||
```json
|
```json
|
||||||
@@ -32,11 +33,18 @@ Actions to assume it:
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
Note: if you are running in a GitHub environment based workflow, the value
|
||||||
|
for the Sub claim will be different, in the form of
|
||||||
|
`repo:<GITHUB_ORG>/<GITHUB_REPOSITORY>:environment:<ENVIRONMENT_NAME>`.
|
||||||
|
Adjust the trust policy accordingly if you are using environment-based
|
||||||
|
workflows.
|
||||||
|
|
||||||
3. Attach permissions to the IAM Role that allow it to access the AWS resources
|
3. Attach permissions to the IAM Role that allow it to access the AWS resources
|
||||||
you need.
|
you need.
|
||||||
4. Add the following to your GitHub Actions workflow:
|
4. Add the following to your GitHub Actions workflow: <details>
|
||||||
<details>
|
|
||||||
<summary>Example Workflow</summary>
|
<summary>Example Workflow</summary>
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
@@ -48,7 +56,7 @@ you need.
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Configure AWS Credentials
|
- name: Configure AWS Credentials
|
||||||
uses: aws-actions/configure-aws-credentials@main # Or a specific version
|
uses: aws-actions/configure-aws-credentials@v6.1.0
|
||||||
with:
|
with:
|
||||||
role-to-assume: <Role ARN you created in step 2>
|
role-to-assume: <Role ARN you created in step 2>
|
||||||
aws-region: <AWS Region you want to use>
|
aws-region: <AWS Region you want to use>
|
||||||
@@ -57,30 +65,38 @@ you need.
|
|||||||
# Your commands that require AWS credentials
|
# Your commands that require AWS credentials
|
||||||
aws sts get-caller-identity
|
aws sts get-caller-identity
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
That's it! Your GitHub Actions workflow can now access AWS resources using the
|
That's it! Your GitHub Actions workflow can now access AWS resources using the
|
||||||
IAM Role you created. Other authentication scenarios are also supported (see
|
IAM Role you created. Other authentication scenarios are also supported (see
|
||||||
below).
|
below).
|
||||||
|
|
||||||
Security Recommendations
|
## Security Recommendations
|
||||||
------------------------
|
|
||||||
* Use temporary credentials when possible. OIDC is recommended because it
|
- Use temporary credentials when possible. OIDC is recommended because it
|
||||||
provides temporary credentials and it's easy to set up.
|
provides temporary credentials and it's easy to set up.
|
||||||
* Do not store credentials in your repository's code. Consider using
|
- Do not store credentials in your repository's code. Consider using
|
||||||
[git-secrets](https://github.com/awslabs/git-secrets) to prevent committing
|
[git-secrets](https://github.com/awslabs/git-secrets) to prevent committing
|
||||||
secrets to your repository.
|
secrets to your repository.
|
||||||
* [Grant least privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege)
|
- [Grant least privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege)
|
||||||
to your workflows. Grant only those permissions that are necessary for the
|
to your workflows. Grant only those permissions that are necessary for the
|
||||||
workflow to run.
|
workflow to run.
|
||||||
* [Monitor the activity](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#keep-a-log)
|
- [Monitor the activity](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#keep-a-log)
|
||||||
of the credentials used in workflows.
|
of the credentials used in workflows.
|
||||||
* Periodically rotate any long-lived credentials that you use.
|
- Periodically rotate any long-lived credentials that you use.
|
||||||
* Store sensitive information in a secure way, such as using
|
- Store sensitive information in a secure way, such as using
|
||||||
[AWS Secrets Manager](https://aws.amazon.com/secrets-manager/) or
|
[AWS Secrets Manager](https://aws.amazon.com/secrets-manager/) or [GitHub
|
||||||
[GitHub Secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets).
|
Secrets][gh-secrets].
|
||||||
|
- Be especially careful about running Actions in non-ephemeral environments, or
|
||||||
|
[triggering workflows on `pull_request_target`](https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#pull_request_target)
|
||||||
|
events.
|
||||||
|
|
||||||
|
[gh-secrets]:
|
||||||
|
https://docs.github.com/en/actions/security-guides/encrypted-secrets
|
||||||
|
|
||||||
|
## Non-OIDC Authentication Options
|
||||||
|
|
||||||
Other Authentication Scenarios
|
|
||||||
------------------------------
|
|
||||||
This action supports five different authentication methods that are configured
|
This action supports five different authentication methods that are configured
|
||||||
by specifying different inputs.
|
by specifying different inputs.
|
||||||
|
|
||||||
@@ -95,40 +111,50 @@ by specifying different inputs.
|
|||||||
credentials via STS AssumeRole.
|
credentials via STS AssumeRole.
|
||||||
|
|
||||||
Because we use the AWS JavaScript SDK, we always will use the [credential
|
Because we use the AWS JavaScript SDK, we always will use the [credential
|
||||||
resolution flow for Node.js](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html).
|
resolution flow for Node.js][cred-resolution].
|
||||||
|
|
||||||
|
[cred-resolution]:
|
||||||
|
https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html
|
||||||
|
|
||||||
Depending on your inputs, the action might override parts of this flow.
|
Depending on your inputs, the action might override parts of this flow.
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>Inputs and their effects on the credential resolution flow</summary>
|
<summary>Inputs and their effects on the credential resolution flow</summary>
|
||||||
|
|
||||||
| **Identity Used** | `aws-access-key-id` | `role-to-assume` | `web-identity-token-file` | `role-chaining` |
|
| **Identity Used** | `aws-access-key-id` | `role-to-assume` | `web-identity-token-file` | `role-chaining` |
|
||||||
| ---------------------------------------- | ------------------- | ---------------- | ------------------------- | --------------- |
|
| --------------------------------------- | ------------------- | ---------------- | ------------------------- | --------------- |
|
||||||
| [✅ Recommended] GitHub OIDC | | ✔ | | |
|
| [✅ Recommended] GitHub OIDC | | ✔ | | |
|
||||||
| IAM User (no AssumeRole) | ✔ | | | |
|
| IAM User (no AssumeRole) | ✔ | | | |
|
||||||
| AssumeRole using static IAM credentials | ✔ | ✔ | | |
|
| AssumeRole using static IAM credentials | ✔ | ✔ | | |
|
||||||
| AssumeWithWebIdentity use a token file | | ✔ | ✔ | |
|
| AssumeWithWebIdentity use a token file | | ✔ | ✔ | |
|
||||||
| AssumeRole using existing credentials | | ✔ | | ✔ |
|
| AssumeRole using existing credentials | | ✔ | | ✔ |
|
||||||
|
|
||||||
*Note: `role-chaining` is not always necessary to use existing credentials.
|
_Note: `role-chaining` is not always necessary to use existing credentials. If
|
||||||
If you're getting a "Credentials loaded by the SDK do not match" error,
|
you're getting a "Credentials loaded by the SDK do not match" error, try
|
||||||
try enabling this option.*
|
enabling this option._
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
Additionally, **`aws-region`** is always required.
|
Additionally, **`aws-region`** is always required.
|
||||||
|
|
||||||
*Note: If you use GitHub Enterprise Server, you must use the you may need to
|
_Note: If you use GitHub Enterprise Server, you may need to adjust examples here
|
||||||
adjust examples here to match your environment.*
|
to match your environment._
|
||||||
|
|
||||||
|
## Additional Options
|
||||||
|
|
||||||
Additional Options
|
|
||||||
------------------
|
|
||||||
### Options
|
### Options
|
||||||
See [action.yml](./action.yml) for more detail.
|
|
||||||
|
The options list can be expanded below. See [action.yml](./action.yml) for more
|
||||||
|
detail.
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>Options list and descriptions</summary>
|
<summary>Options list and descriptions</summary>
|
||||||
|
|
||||||
| Option | Description | Required |
|
| Option | Description | Required |
|
||||||
|---------------------------|---------------------------------------------------------------------------------------------------|----------|
|
| ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
|
||||||
| aws-region | Which AWS region to use | Yes |
|
| aws-region | Which AWS region to use | Yes |
|
||||||
|
| aws-profile | Name of the AWS profile to configure. When provided, credentials are written to `~/.aws/credentials` and `~/.aws/config` files. This enables configuring multiple profiles in a single workflow. Name cannot contain whitespace, square brackets, or slashes. When set, credentials will not be exported as environment variables unless `output-env-credentials` is manually set to true. | No |
|
||||||
|
| overwrite-aws-profile | Overwrite the given AWS profile if it already exists. When set to false or not set, an error will be thrown if the profile already exists. | No |
|
||||||
| role-to-assume | Role for which to fetch credentials. Only required for some authentication types. | No |
|
| role-to-assume | Role for which to fetch credentials. Only required for some authentication types. | No |
|
||||||
| aws-access-key-id | AWS access key to use. Only required for some authentication types. | No |
|
| aws-access-key-id | AWS access key to use. Only required for some authentication types. | No |
|
||||||
| aws-secret-access-key | AWS secret key to use. Only required for some authentication types. | No |
|
| aws-secret-access-key | AWS secret key to use. Only required for some authentication types. | No |
|
||||||
@@ -141,33 +167,134 @@ See [action.yml](./action.yml) for more detail.
|
|||||||
| role-external-id | The external ID of the role to assume. Only needed if your role requires it. | No |
|
| role-external-id | The external ID of the role to assume. Only needed if your role requires it. | No |
|
||||||
| role-session-name | Defaults to "GitHubActions", but may be changed if required. | No |
|
| role-session-name | Defaults to "GitHubActions", but may be changed if required. | No |
|
||||||
| role-skip-session-tagging | Skips session tagging if set. | No |
|
| role-skip-session-tagging | Skips session tagging if set. | No |
|
||||||
|
| transitive-tag-keys | Define a list of transitive tag keys to pass when assuming a role. | No |
|
||||||
|
| custom-tags | Additional tags to apply to the assumed role session. Must be a JSON object provided as a string. Custom tags are not usable with OIDC or web identity token authentication. | No |
|
||||||
| inline-session-policy | You may further restrict the assumed role policy by defining an inline policy here. | No |
|
| inline-session-policy | You may further restrict the assumed role policy by defining an inline policy here. | No |
|
||||||
| managed-session-policies | You may further restrict the assumed role policy by specifying a managed policy here. | No |
|
| managed-session-policies | You may further restrict the assumed role policy by specifying a managed policy here. | No |
|
||||||
| output-credentials | When set, outputs fetched credentials as action step output. (Outputs aws-access-key-id, aws-secret-access-key, aws-session-token, aws-account-id, authenticated-arn, and aws-expiration). Defaults to false. | No |
|
| output-credentials | When set, outputs fetched credentials as action step output. (Outputs aws-access-key-id, aws-secret-access-key, aws-session-token, aws-account-id, authenticated-arn, and aws-expiration). Defaults to false. | No |
|
||||||
| output-env-credentials | When set, outputs fetched credentials as environment variables (AWS_REGION, AWS_DEFAULT_REGION, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN). Defaults to true. Set to false if you need to avoid setting/changing env variables. You'd probably want to use output-credentials if you disable this. (NOTE: Setting to false will prevent the aws-account-id from being exported as a step output). | No |
|
| output-env-credentials | When set, outputs fetched credentials as environment variables (AWS_REGION, AWS_DEFAULT_REGION, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN, and AWS_PROFILE (if profile option is used)). Defaults to true when `aws-profile` is not set, and false when `aws-profile` is set. Set to false to avoid setting env variables. (NOTE: Setting to false will prevent aws-account-id from being exported as a step output). | No |
|
||||||
| unset-current-credentials | When set, attempts to unset any existing credentials in your action runner. | No |
|
| unset-current-credentials | When set, attempts to unset any existing credentials in your action runner. | No |
|
||||||
| disable-retry | Disabled retry/backoff logic for assume role calls. By default, retries are enabled. | No |
|
| disable-retry | Disabled retry/backoff logic for assume role calls. By default, retries are enabled. | No |
|
||||||
| retry-max-attempts | Limits the number of retry attempts before giving up. Defaults to 12. | No |
|
| retry-max-attempts | Limits the number of retry attempts before giving up. Defaults to 12. | No |
|
||||||
| special-characters-workaround | Uncommonly, some environments cannot tolerate special characters in a secret key. This option will retry fetching credentials until the secret access key does not contain special characters. This option overrides disable-retry and retry-max-attempts. | No |
|
| special-characters-workaround | Uncommonly, some environments cannot tolerate special characters in a secret key. This option will retry fetching credentials until the secret access key does not contain special characters. This option overrides disable-retry and retry-max-attempts. | No |
|
||||||
| use-existing-credentials | When set, the action will check if existing credentials are valid and exit if they are. Defaults to false. | No |
|
| use-existing-credentials | When set, the action will check if existing credentials are valid and exit if they are. Defaults to false. | No |
|
||||||
|
| allowed-account-ids | A comma-delimited list of expected AWS account IDs. The action will fail if we receive credentials for the wrong account. | No |
|
||||||
|
| force-skip-oidc | When set, the action will skip using GitHub OIDC provider even if the id-token permission is set. | No |
|
||||||
|
| action-timeout-s | Global timeout for the action in seconds. If set to a value greater than 0, the action will fail if it takes longer than this time to complete. | No |
|
||||||
|
| no-proxy | Hosts to skip for the proxy configuration. | No |
|
||||||
|
| sts-endpoint | Custom STS endpoint URL. Use this to point to an STS-compatible API (e.g. MinIO, LocalStack) instead of the default AWS STS endpoint for the region. | No |
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
#### Adjust the retry mechanism
|
#### Adjust the retry mechanism
|
||||||
You can configure retry settings for if the STS call fails. By default, we
|
|
||||||
retry with exponential backoff `12` times. You can disable this behavior
|
You can configure retry settings for if the STS call fails. By default, we retry
|
||||||
altogether by setting the `disable-retry` input to `true`, or you can configure
|
with exponential backoff `12` times. You can disable this behavior altogether by
|
||||||
the number of times it retries with the `retry-max-attempts` input.
|
setting the `disable-retry` input to `true`, or you can configure the number of
|
||||||
|
times it retries with the `retry-max-attempts` input.
|
||||||
|
|
||||||
#### Mask account ID
|
#### Mask account ID
|
||||||
|
|
||||||
Your account ID is not masked by default in workflow logs. You can set the
|
Your account ID is not masked by default in workflow logs. You can set the
|
||||||
`mask-aws-account-id` input to `true` to mask your account ID in workflow logs
|
`mask-aws-account-id` input to `true` to mask your account ID in workflow logs
|
||||||
if desired.
|
if desired.
|
||||||
|
|
||||||
#### Unset current credentials
|
#### Unset current credentials
|
||||||
|
|
||||||
Sometimes, existing credentials in your runner can get in the way of the
|
Sometimes, existing credentials in your runner can get in the way of the
|
||||||
intended outcome. You can set the `unset-current-credentials` input to `true` to
|
intended outcome. You can set the `unset-current-credentials` input to `true` to
|
||||||
work around this issue.
|
work around this issue.
|
||||||
|
|
||||||
|
#### Configure named AWS profiles
|
||||||
|
|
||||||
|
By default, this action exports credentials as environment variables
|
||||||
|
(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, etc.). However, you can use the
|
||||||
|
`aws-profile` input to configure named AWS profiles. When `aws-profile` is
|
||||||
|
provided, credentials are written to `~/.aws/credentials` and `~/.aws/config`
|
||||||
|
files (which are created if they don't already exist). The default locations of
|
||||||
|
these files will be overridden if the `AWS_SHARED_CREDENTIALS_FILE` and
|
||||||
|
`AWS_CONFIG_FILE` environment variables are present.
|
||||||
|
|
||||||
|
Profile names may not contain whitespace, square brackets, or forward or
|
||||||
|
backslashes.
|
||||||
|
|
||||||
|
Writing to a profile will prevent credentials being written to the environment
|
||||||
|
by default. Use `output-env-credentials: true` if you would like the credentials
|
||||||
|
to also be exported as environment variables.
|
||||||
|
|
||||||
|
By default, the action will not overwrite existing profiles. If you would like
|
||||||
|
to overwrite a profile, set the `overwrite-aws-profile` input to `true`.
|
||||||
|
|
||||||
|
_Note: When writing profiles, the action will preserve existing profile sections
|
||||||
|
in the credentials and config files. However, comments in these files will not
|
||||||
|
be preserved._
|
||||||
|
|
||||||
|
_Caution: Writing to the AWS configuration file means that credentials will
|
||||||
|
persist in the execution environment even after the action cleanup step. Use
|
||||||
|
extreme care to ensure that this is safe in your environment and you do not leak
|
||||||
|
valid credentials unintentionally. Writing to configuration files is intended
|
||||||
|
for unusual authentication scenarios._
|
||||||
|
|
||||||
|
For using profiles with static IAM User Credentials or when using one role to
|
||||||
|
assume another, role chaining is needed:
|
||||||
|
|
||||||
|
<details>
|
||||||
|
|
||||||
|
If using static credentials, it's necessary to set `role-chaining: true` and
|
||||||
|
specify the profile name as an environment variable in the job step:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- name: Configure AWS Credentials
|
||||||
|
uses: aws-actions/configure-aws-credentials@v6.1.0
|
||||||
|
with:
|
||||||
|
aws-region: us-east-1
|
||||||
|
role-to-assume: arn:aws:iam::123456789100:role/my-role
|
||||||
|
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||||
|
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||||
|
aws-profile: MyProfile1
|
||||||
|
role-chaining: true
|
||||||
|
env:
|
||||||
|
AWS_PROFILE: MyProfile1
|
||||||
|
```
|
||||||
|
|
||||||
|
If you are using one role to assume another while using profiles, the subsequent
|
||||||
|
steps must set `role-chaining: true` and specify the prior profile's name as
|
||||||
|
step environment variables:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- name: Configure AWS credentials
|
||||||
|
uses: aws-actions/configure-aws-credentials@v6.1.0
|
||||||
|
with:
|
||||||
|
aws-region: us-east-1
|
||||||
|
role-to-assume: arn:aws:iam::123456789100:role/my-first-role
|
||||||
|
aws-profile: firstRoleInChain
|
||||||
|
|
||||||
|
- name: assume second role
|
||||||
|
uses: aws-actions/configure-aws-credentials@v6.1.0
|
||||||
|
with:
|
||||||
|
aws-region: us-east-2
|
||||||
|
role-to-assume: arn:aws:iam::987654321000:role/my-second-role
|
||||||
|
role-chaining: true
|
||||||
|
aws-profile: secondRoleInChain
|
||||||
|
env:
|
||||||
|
AWS_PROFILE: firstRoleInChain
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
See the [Examples](#examples) section for more usage examples.
|
||||||
|
|
||||||
|
#### Skip the cleanup
|
||||||
|
|
||||||
|
By default, this action runs a post-job cleanup step that removes credentials
|
||||||
|
from the environment. To skip this step, set the `AWS_SKIP_CLEANUP_STEP`
|
||||||
|
environment variable to `true`:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
env:
|
||||||
|
AWS_SKIP_CLEANUP_STEP: "true"
|
||||||
|
```
|
||||||
|
|
||||||
#### Use an HTTP proxy
|
#### Use an HTTP proxy
|
||||||
|
|
||||||
If need use an HTTP proxy you can set it in the action manually. Additionally
|
If need use an HTTP proxy you can set it in the action manually. Additionally
|
||||||
@@ -177,8 +304,9 @@ this action will always consider the `HTTP_PROXY` environment variable.
|
|||||||
<summary>Proxy configuration</summary>
|
<summary>Proxy configuration</summary>
|
||||||
|
|
||||||
Manually configured proxy:
|
Manually configured proxy:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
uses: aws-actions/configure-aws-credentials@v4.3.1
|
uses: aws-actions/configure-aws-credentials@v6.1.0
|
||||||
with:
|
with:
|
||||||
aws-region: us-east-2
|
aws-region: us-east-2
|
||||||
role-to-assume: my-github-actions-role
|
role-to-assume: my-github-actions-role
|
||||||
@@ -186,16 +314,23 @@ with:
|
|||||||
```
|
```
|
||||||
|
|
||||||
Proxy configured in the environment variable:
|
Proxy configured in the environment variable:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Your environment configuration
|
# Your environment configuration
|
||||||
HTTP_PROXY="http://companydomain.com:3128"
|
HTTP_PROXY="http://companydomain.com:3128"
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
#### Special characters in AWS_SECRET_ACCESS_KEY
|
#### Special characters in AWS_SECRET_ACCESS_KEY
|
||||||
|
|
||||||
Some edge cases are unable to properly parse an `AWS_SECRET_ACCESS_KEY` if it
|
Some edge cases are unable to properly parse an `AWS_SECRET_ACCESS_KEY` if it
|
||||||
contains special characters. For more information, please see the
|
contains special characters. For more information, please see the [AWS CLI
|
||||||
[AWS CLI documentation](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-troubleshooting.html#tshoot-signature-does-not-match).
|
documentation][aws-cli-troubleshooting].
|
||||||
|
|
||||||
|
[aws-cli-troubleshooting]:
|
||||||
|
https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-troubleshooting.html#tshoot-signature-does-not-match
|
||||||
|
|
||||||
If you set the `special-characters-workaround` option, this action will
|
If you set the `special-characters-workaround` option, this action will
|
||||||
continually retry fetching credentials until we get one that does not have
|
continually retry fetching credentials until we get one that does not have
|
||||||
special characters. This option overrides the `disable-retry` and
|
special characters. This option overrides the `disable-retry` and
|
||||||
@@ -203,18 +338,22 @@ special characters. This option overrides the `disable-retry` and
|
|||||||
unless required, because retrying APIs infinitely until they succeed is not best
|
unless required, because retrying APIs infinitely until they succeed is not best
|
||||||
practice.
|
practice.
|
||||||
|
|
||||||
Session Naming and Policies
|
## Session Naming and Policies
|
||||||
---------------------------
|
|
||||||
The default session name is "GitHubActions", and you can modify it by specifying
|
The default session name is "GitHubActions", and you can modify it by specifying
|
||||||
the desired name in `role-session-name`.
|
the desired name in `role-session-name`.
|
||||||
|
|
||||||
*Note: you might find it helpful to set the `role-session-name` to `${{ github.run_id }}`
|
_Note: you might find it helpful to set the `role-session-name` to
|
||||||
so as to clarify in audit logs which AWS actions were performed by which workflow
|
`${{ github.run_id }}` so as to clarify in audit logs which AWS actions were
|
||||||
run.*
|
performed by which workflow run._
|
||||||
|
|
||||||
The session will be tagged with the
|
The session will be tagged with the following tags: (Refer to [GitHub's
|
||||||
following tags: (Refer to [GitHub's documentation for `GITHUB_` environment
|
documentation for `GITHUB_` environment variable definitions][gh-env-vars])
|
||||||
variable definitions](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/using-environment-variables#default-environment-variables))
|
|
||||||
|
[gh-env-vars]:
|
||||||
|
https://docs.github.com/en/actions/reference/workflows-and-actions/variables#default-environment-variables
|
||||||
|
|
||||||
|
**Default tags** are always emitted when session tags are used.
|
||||||
|
|
||||||
| Key | Value |
|
| Key | Value |
|
||||||
| ---------- | ----------------- |
|
| ---------- | ----------------- |
|
||||||
@@ -223,24 +362,89 @@ variable definitions](https://help.github.com/en/actions/automating-your-workflo
|
|||||||
| Workflow | GITHUB_WORKFLOW |
|
| Workflow | GITHUB_WORKFLOW |
|
||||||
| Action | GITHUB_ACTION |
|
| Action | GITHUB_ACTION |
|
||||||
| Actor | GITHUB_ACTOR |
|
| Actor | GITHUB_ACTOR |
|
||||||
| Branch | GITHUB_REF |
|
|
||||||
| Commit | GITHUB_SHA |
|
| Commit | GITHUB_SHA |
|
||||||
|
| Branch | GITHUB_REF |
|
||||||
|
|
||||||
|
**Droppable tags** are automatically added to the set of default session tags.
|
||||||
|
If the session tags exceed the [packed size limit][packed-size-limit], these
|
||||||
|
tags will be dropped, and the AssumeRole call will be retried. If it still
|
||||||
|
fails, the action will error out. (It is difficult to predict the packed size
|
||||||
|
before making the call, as session tags and session policies are compressed into
|
||||||
|
a binary format as part of the call.)
|
||||||
|
|
||||||
|
[packed-size-limit]:
|
||||||
|
https://docs.aws.amazon.com/IAM/latest/UserGuide/id_session-tags.html#id_session-tags_know
|
||||||
|
|
||||||
|
| Key | Value |
|
||||||
|
| --------------- | ----------------------- |
|
||||||
|
| EventName | GITHUB_EVENT_NAME |
|
||||||
|
| BaseRef | GITHUB_BASE_REF |
|
||||||
|
| HeadRef | GITHUB_HEAD_REF |
|
||||||
|
| RunId | GITHUB_RUN_ID |
|
||||||
|
| Job | GITHUB_JOB |
|
||||||
|
| TriggeringActor | GITHUB_TRIGGERING_ACTOR |
|
||||||
|
|
||||||
|
Tags whose source environment variable is unset are omitted (e.g., `BaseRef` and
|
||||||
|
`HeadRef` are only set on `pull_request` events).
|
||||||
|
|
||||||
_Note: all tag values must conform to
|
_Note: all tag values must conform to
|
||||||
[the tag requirements](https://docs.aws.amazon.com/STS/latest/APIReference/API_Tag.html).
|
[the tag requirements][sts-tag-requirements].
|
||||||
Particularly, `GITHUB_WORKFLOW` will be truncated if it's too long. If
|
Values longer than 256 characters will be truncated, and characters outside the
|
||||||
`GITHUB_ACTOR` or `GITHUB_WORKFLOW` contain invalid characters, the characters
|
allowed set will be replaced with an underscore (`_`)._
|
||||||
will be replaced with an '*'._
|
|
||||||
|
|
||||||
The action will use session tagging by default unless you are using OIDC.
|
[sts-tag-requirements]:
|
||||||
|
https://docs.aws.amazon.com/STS/latest/APIReference/API_Tag.html
|
||||||
|
|
||||||
|
The action will use session tagging by default unless you are using OIDC or a
|
||||||
|
Web Identify Token File.
|
||||||
|
|
||||||
|
To [forward session tags to subsequent sessions in a role
|
||||||
|
chain][session-tag-chaining], you can use the `transitive-tag-keys` input to
|
||||||
|
specify the keys of the tags to be passed.
|
||||||
|
|
||||||
|
[session-tag-chaining]:
|
||||||
|
https://docs.aws.amazon.com/IAM/latest/UserGuide/id_session-tags.html#id_session-tags_role-chaining
|
||||||
|
|
||||||
|
_Note that all subsequent roles in the chain must have
|
||||||
|
`role-skip-session-tagging` set to `true`_
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
uses: aws-actions/configure-aws-credentials@v6
|
||||||
|
with:
|
||||||
|
transitive-tag-keys: |
|
||||||
|
Repository
|
||||||
|
Workflow
|
||||||
|
Action
|
||||||
|
Actor
|
||||||
|
```
|
||||||
|
|
||||||
|
### Custom session tags
|
||||||
|
|
||||||
|
You can add custom session tags using the `custom-tags` input, which accepts a
|
||||||
|
JSON object. Custom tags cannot override existing tags. Note that AWS allows a
|
||||||
|
maximum of 50 tags (so you can supply a maximum of 43 custom tags), although it
|
||||||
|
is likely that you will exceed the [packed size limit][packed-size-limit]
|
||||||
|
before you exceed the maximum number of tags.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
uses: aws-actions/configure-aws-credentials@v6
|
||||||
|
with:
|
||||||
|
custom-tags: '{"Environment": "Production", "Team": "Platform"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
_Note: custom tags are not supported when using OIDC or web identity token
|
||||||
|
authentication. In those flows, session tags are controlled by the identity
|
||||||
|
provider's token claims._
|
||||||
|
|
||||||
### Session policies
|
### Session policies
|
||||||
|
|
||||||
Session policies are not required, but they allow you to limit the scope of the
|
Session policies are not required, but they allow you to limit the scope of the
|
||||||
fetched credentials without making changes to IAM roles. You can specify inline
|
fetched credentials without making changes to IAM roles. You can specify inline
|
||||||
session policies right in your workflow file, or refer to an existing managed
|
session policies right in your workflow file, or refer to an existing managed
|
||||||
session policy by its ARN.
|
session policy by its ARN.
|
||||||
|
|
||||||
#### Inline session policies
|
#### Inline session policies
|
||||||
|
|
||||||
An IAM policy in stringified JSON format that you want to use as an inline
|
An IAM policy in stringified JSON format that you want to use as an inline
|
||||||
session policy. Depending on preferences, the JSON could be written on a single
|
session policy. Depending on preferences, the JSON could be written on a single
|
||||||
line.
|
line.
|
||||||
@@ -249,13 +453,15 @@ line.
|
|||||||
<summary>Inline session policy examples</summary>
|
<summary>Inline session policy examples</summary>
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
uses: aws-actions/configure-aws-credentials@v4.3.1
|
uses: aws-actions/configure-aws-credentials@v6.1.0
|
||||||
with:
|
with:
|
||||||
inline-session-policy: '{"Version":"2012-10-17","Statement":[{"Sid":"Stmt1","Effect":"Allow","Action":"s3:List*","Resource":"*"}]}'
|
inline-session-policy: '{"Version":"2012-10-17","Statement":[{"Sid":"Stmt1","Effect":"Allow","Action":"s3:List*","Resource":"*"}]}'
|
||||||
```
|
```
|
||||||
|
|
||||||
Or we can have a nicely formatted JSON as well:
|
Or we can have a nicely formatted JSON as well:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
uses: aws-actions/configure-aws-credentials@v4.3.1
|
uses: aws-actions/configure-aws-credentials@v6.1.0
|
||||||
with:
|
with:
|
||||||
inline-session-policy: >-
|
inline-session-policy: >-
|
||||||
{
|
{
|
||||||
@@ -270,9 +476,11 @@ Or we can have a nicely formatted JSON as well:
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
#### Managed session policies
|
#### Managed session policies
|
||||||
|
|
||||||
The Amazon Resource Names (ARNs) of the IAM managed policies that you want to
|
The Amazon Resource Names (ARNs) of the IAM managed policies that you want to
|
||||||
use as managed session policies. The policies must exist in the same account as
|
use as managed session policies. The policies must exist in the same account as
|
||||||
the role.
|
the role.
|
||||||
@@ -281,36 +489,46 @@ the role.
|
|||||||
<summary>Managed session policy examples</summary>
|
<summary>Managed session policy examples</summary>
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
uses: aws-actions/configure-aws-credentials@v4.3.1
|
uses: aws-actions/configure-aws-credentials@v6.1.0
|
||||||
with:
|
with:
|
||||||
managed-session-policies: arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess
|
managed-session-policies: arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess
|
||||||
```
|
```
|
||||||
|
|
||||||
And we can pass multiple managed policies likes this:
|
And we can pass multiple managed policies likes this:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
uses: aws-actions/configure-aws-credentials@v4.3.1
|
uses: aws-actions/configure-aws-credentials@v6.1.0
|
||||||
with:
|
with:
|
||||||
managed-session-policies: |
|
managed-session-policies: |
|
||||||
arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess
|
arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess
|
||||||
arn:aws:iam::aws:policy/AmazonS3OutpostsReadOnlyAccess
|
arn:aws:iam::aws:policy/AmazonS3OutpostsReadOnlyAccess
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
OIDC Configuration
|
### Custom STS endpoint
|
||||||
-------------------
|
|
||||||
We recommend using [GitHub's OIDC
|
Use the `sts-endpoint` input to override the AWS STS endpoint URL. Most users
|
||||||
provider](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services)
|
should not set this option and instead let the SDK derive the correct endpoint
|
||||||
|
from the specified region.
|
||||||
|
|
||||||
|
## OIDC Configuration Details
|
||||||
|
|
||||||
|
We recommend using
|
||||||
|
[GitHub's OIDC provider](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services)
|
||||||
to get short-lived AWS credentials needed for your actions. When using OIDC, you
|
to get short-lived AWS credentials needed for your actions. When using OIDC, you
|
||||||
configure IAM to accept JWTs from GitHub's OIDC endpoint. This action will
|
configure IAM to accept JWTs from GitHub's OIDC endpoint. This action will then
|
||||||
then create a JWT unique to the workflow run using the OIDC endpoint, and it
|
create a JWT unique to the workflow run using the OIDC endpoint, and it will use
|
||||||
will use the JWT to assume the specified role with short-term credentials.
|
the JWT to assume the specified role with short-term credentials.
|
||||||
|
|
||||||
To get this to work
|
To get this to work
|
||||||
|
|
||||||
1. Configure your workflow to use the `id-token: write` permission.
|
1. Configure your workflow to use the `id-token: write` permission.
|
||||||
2. Configure your audience, if required.
|
2. Configure your audience, if required.
|
||||||
3. In your AWS account, configure IAM to trust GitHub's OIDC identity provider.
|
3. In your AWS account, configure IAM to trust GitHub's OIDC identity provider.
|
||||||
4. Configure an IAM role with appropriate claim limits and permission scope.
|
4. Configure an IAM role with appropriate claim limits and permission scope.
|
||||||
|
|
||||||
*Note*: Naming your role "GitHubActions" has been reported to not work. See
|
_Note_: Naming your role "GitHubActions" has been reported to not work. See
|
||||||
[#953](https://github.com/aws-actions/configure-aws-credentials/issues/953).
|
[#953](https://github.com/aws-actions/configure-aws-credentials/issues/953).
|
||||||
|
|
||||||
5. Specify that role's ARN when setting up this action.
|
5. Specify that role's ARN when setting up this action.
|
||||||
@@ -319,13 +537,13 @@ To get this to work
|
|||||||
|
|
||||||
When the JWT is created, an audience needs to be specified. Normally, you would
|
When the JWT is created, an audience needs to be specified. Normally, you would
|
||||||
use `sts.amazonaws.com`, and this action uses this by default if you don't
|
use `sts.amazonaws.com`, and this action uses this by default if you don't
|
||||||
specify one. This will work for most cases. Changing the default audience may
|
specify one. This will work for most cases. Changing the default audience may be
|
||||||
be necessary when using non-default AWS partitions, such as China regions.
|
necessary when using non-default AWS partitions, such as China regions. You can
|
||||||
You can specify the audience through the `audience` input:
|
specify the audience through the `audience` input:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Configure AWS Credentials for China region audience
|
- name: Configure AWS Credentials for China region audience
|
||||||
uses: aws-actions/configure-aws-credentials@v4.3.1
|
uses: aws-actions/configure-aws-credentials@v6.1.0
|
||||||
with:
|
with:
|
||||||
audience: sts.amazonaws.com.cn
|
audience: sts.amazonaws.com.cn
|
||||||
aws-region: cn-northwest-1
|
aws-region: cn-northwest-1
|
||||||
@@ -333,10 +551,12 @@ You can specify the audience through the `audience` input:
|
|||||||
```
|
```
|
||||||
|
|
||||||
### Configuring IAM to trust GitHub
|
### Configuring IAM to trust GitHub
|
||||||
|
|
||||||
To use GitHub's OIDC provider, you must first set up federation in your AWS
|
To use GitHub's OIDC provider, you must first set up federation in your AWS
|
||||||
account. This involves creating an IAM Identity Provider that trusts GitHub's
|
account. This involves creating an IAM Identity Provider that trusts GitHub's
|
||||||
OIDC endpoint. You can create an IAM Identity Provider in the AWS Management
|
OIDC endpoint. You can create an IAM Identity Provider in the AWS Management
|
||||||
Console by specifying the following details:
|
Console by specifying the following details:
|
||||||
|
|
||||||
- **Provider Type**: OIDC
|
- **Provider Type**: OIDC
|
||||||
- **Provider URL**: `https://token.actions.githubusercontent.com`
|
- **Provider URL**: `https://token.actions.githubusercontent.com`
|
||||||
- **Audience**: `sts.amazonaws.com` (or your custom audience if you specified
|
- **Audience**: `sts.amazonaws.com` (or your custom audience if you specified
|
||||||
@@ -355,86 +575,156 @@ aws iam create-open-id-connect-provider \
|
|||||||
```
|
```
|
||||||
|
|
||||||
### Claims and scoping permissions
|
### Claims and scoping permissions
|
||||||
|
|
||||||
To align with the Amazon IAM best practice of [granting least
|
To align with the Amazon IAM best practice of [granting least
|
||||||
privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege),
|
privilege][least-privilege], the assume role policy document should contain a
|
||||||
the assume role policy document should contain a
|
|
||||||
[`Condition`](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition.html)
|
[`Condition`](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition.html)
|
||||||
that specifies a subject (`sub`) allowed to assume the role. [GitHub also
|
that restricts which workflows can assume the role. Without any condition, any
|
||||||
recommends](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect#defining-trust-conditions-on-cloud-roles-using-oidc-claims)
|
GitHub user or repository could potentially assume the role.
|
||||||
filtering for the correct audience (`aud`). See [AWS IAM
|
|
||||||
documentation](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_iam-condition-keys.html#condition-keys-wif)
|
|
||||||
on which claims you can filter for in your trust policies.
|
|
||||||
|
|
||||||
Without a subject (`sub`) condition, any GitHub user or repository could
|
GitHub provides a number of additional claims in the OIDC token that you can use
|
||||||
potentially assume the role. The subject can be scoped to a GitHub organization
|
in your IAM policies to scope down permissions. Early versions of this action
|
||||||
and repository as shown in the CloudFormation template. However, scoping it down
|
only supported the `sub` and `aud` claims, but AWS IAM and GitHub have since
|
||||||
to your org and repo may cause the role assumption to fail in some cases. See
|
added support for `sub` claim customization and a variety of additional
|
||||||
[Example subject claims](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect#example-subject-claims)
|
claims ([1][gh-blog-oidc], [2][sub-claim-custom]).
|
||||||
for specific details on what the subject value will be depending on your
|
|
||||||
workflow. You can also [customize your subject claim](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect#customizing-the-token-claims)
|
> **Warning:** Avoid `ForAllValues:` in `Allow` statements. These operators
|
||||||
if you want full control over the information you can filter for in your trust
|
> return true when the claim is absent or misspelled, which can lead to
|
||||||
policy. If you aren't sure what your subject (`sub`) key is, you can add the
|
> unintended access. Instead, use `StringEquals` or `StringLike` operators to
|
||||||
|
> check for specific claim values.
|
||||||
|
|
||||||
|
[least-privilege]:
|
||||||
|
https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege
|
||||||
|
[gh-blog-oidc]:
|
||||||
|
https://aws.amazon.com/about-aws/whats-new/2026/01/aws-sts-supports-validation-identity-provider-claims/
|
||||||
|
[sub-claim-custom]:
|
||||||
|
https://docs.github.com/en/rest/actions/oidc?apiVersion=2026-03-10
|
||||||
|
|
||||||
|
#### Inspecting the token
|
||||||
|
|
||||||
|
If you aren't sure what claim values your workflow is producing, the
|
||||||
[`actions-oidc-debugger`](https://github.com/github/actions-oidc-debugger)
|
[`actions-oidc-debugger`](https://github.com/github/actions-oidc-debugger)
|
||||||
action to your workflow to see the value of the subject (`sub`) key, as well as
|
action will print the decoded JWT payload. Run it in a private repository
|
||||||
other claims.
|
only — the token itself is short-lived but the claim values may be sensitive.
|
||||||
|
|
||||||
Additional claim conditions can be added for higher specificity as explained in
|
See the GitHub [security-hardening guide][gh-oidc-hardening] for further
|
||||||
the [GitHub documentation](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect).
|
discussion of trust conditions and threat modeling.
|
||||||
Due to implementation details, not every OIDC claim is presently supported by
|
|
||||||
IAM.
|
[gh-oidc-hardening]:
|
||||||
|
https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect
|
||||||
|
|
||||||
### Further information about OIDC
|
### Further information about OIDC
|
||||||
|
|
||||||
For further information on OIDC and GitHub Actions, please see:
|
For further information on OIDC and GitHub Actions, please see:
|
||||||
|
|
||||||
* [AWS docs: Creating OpenID Connect (OIDC) identity providers](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_create_oidc.html)
|
- [AWS docs: Creating OpenID Connect (OIDC) identity providers](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_create_oidc.html)
|
||||||
* [AWS docs: IAM JSON policy elements: Condition](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition.html)
|
- [AWS docs: IAM JSON policy elements: Condition](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition.html)
|
||||||
* [GitHub docs: About security hardening with OpenID Connect](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
|
- [GitHub docs: About security hardening with OpenID Connect](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
|
||||||
* [GitHub docs: Configuring OpenID Connect in Amazon Web Services](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services)
|
- [GitHub docs: Configuring OpenID Connect in Amazon Web Services](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services)
|
||||||
* [GitHub changelog: GitHub Actions: Secure cloud deployments with OpenID Connect](https://github.blog/changelog/2021-10-27-github-actions-secure-cloud-deployments-with-openid-connect/)
|
- [GitHub changelog: GitHub Actions: Secure cloud deployments with OpenID Connect](https://github.blog/changelog/2021-10-27-github-actions-secure-cloud-deployments-with-openid-connect/)
|
||||||
|
|
||||||
Examples
|
## Getting Credentials in AWS Self-Hosted Runners
|
||||||
--------
|
|
||||||
|
If you are running GitHub Actions in a self-hosted runner using an AWS Service
|
||||||
|
(such as Codebuild or EKS) and you have properly configured the service,
|
||||||
|
credentials should be available by default; the AWS CLI will fetch credentials
|
||||||
|
using the AWS_CONTAINER_CREDENTIALS_FULL_URI or
|
||||||
|
AWS_CONTAINER_CREDENTIALS_RELATIVE_URI environment variables. However, you may
|
||||||
|
still want to use this action if you need to export those credentials for use
|
||||||
|
with other tools in your workflow. You may also want to use this action in
|
||||||
|
scenarios where you need to use that 'default' role to assume another role.
|
||||||
|
|
||||||
|
To export credentials, simply run the action with `role-to-assume` set to the
|
||||||
|
default role of the container.
|
||||||
|
|
||||||
|
To assume another role from the container's default role, use the
|
||||||
|
`role-chaining: true` flag, so that the action fetches the default credentials
|
||||||
|
from the environment before assuming the other role.
|
||||||
|
|
||||||
|
If you are using EKS Pod Identities and encountering an error related to the
|
||||||
|
packed size of session tags, you must either run the action with
|
||||||
|
`role-skip-session-tagging: true` to disable the tags set by the action, or
|
||||||
|
[disable EKS session tagging][eks-disable-session-tagging] in the EKS settings
|
||||||
|
to disable the tags that are automatically set by the EKS Pod Identity Service.
|
||||||
|
Check the values of the action's session tags and the session tags that are
|
||||||
|
added by EKS so you can keep the set of tags which is more useful to you.
|
||||||
|
|
||||||
|
[eks-disable-session-tagging]:
|
||||||
|
https://docs.aws.amazon.com/eks/latest/userguide/pod-id-abac.html#pod-id-abac-tags
|
||||||
|
|
||||||
|
## Compatibility with non-GitHub Actions environments
|
||||||
|
|
||||||
|
This action has been sucessfully tested with
|
||||||
|
Codeberg/[Forgejo Actions](https://forgejo.org/docs/next/user/actions/overview/)
|
||||||
|
and should be generally compatible with any CI/CD environment that sets the
|
||||||
|
correct `GITHUB_` environment variables. For use with Foregejo, please review
|
||||||
|
the
|
||||||
|
[runner differences with GitHub's action runners][forgejo-gh-differences].
|
||||||
|
|
||||||
|
[forgejo-gh-differences]:
|
||||||
|
https://forgejo.org/docs/next/user/actions/github-actions/#known-list-of-differences
|
||||||
|
The main difference to be aware of is that Forgejo uses the
|
||||||
|
`enable-openid-connect` flag to enable OIDC instad of GitHub's `id-token: write`
|
||||||
|
permission. Forgejo also uses a slightly different syntax for the workflow
|
||||||
|
definition file, omitting some subkeys.
|
||||||
|
|
||||||
|
For OIDC use, the issuer name for the IAM IdP for GitHub Actions is
|
||||||
|
`token.actions.githubusercontent.com`. For Forgejo Actions it is
|
||||||
|
`[foregejo instance url]/api/actions`. As an example, Codeberg would use
|
||||||
|
`codeberg.org/api/actions` as the issuer URL when configuring the IAM Identity
|
||||||
|
Provider. The audience would still be `sts.amazonaws.com` by default.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
### AssumeRoleWithWebIdentity
|
### AssumeRoleWithWebIdentity
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Configure AWS Credentials
|
- name: Configure AWS Credentials
|
||||||
uses: aws-actions/configure-aws-credentials@v4.3.1
|
uses: aws-actions/configure-aws-credentials@v6.1.0
|
||||||
with:
|
with:
|
||||||
aws-region: us-east-2
|
aws-region: us-east-2
|
||||||
role-to-assume: arn:aws:iam::123456789100:role/my-github-actions-role
|
role-to-assume: arn:aws:iam::123456789100:role/my-github-actions-role
|
||||||
role-session-name: MySessionName
|
role-session-name: MySessionName
|
||||||
```
|
```
|
||||||
|
|
||||||
In this example, the Action will load the OIDC token from the GitHub-provided
|
In this example, the Action will load the OIDC token from the GitHub-provided
|
||||||
environment variable and use it to assume the role
|
environment variable and use it to assume the role
|
||||||
`arn:aws:iam::123456789100:role/my-github-actions-role` with the session name
|
`arn:aws:iam::123456789100:role/my-github-actions-role` with the session name
|
||||||
`MySessionName`.
|
`MySessionName`.
|
||||||
|
|
||||||
### AssumeRole with role previously assumed by action in same workflow
|
### AssumeRole with role previously assumed by action in same workflow
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Configure AWS Credentials
|
- name: Configure AWS Credentials
|
||||||
uses: aws-actions/configure-aws-credentials@v4.3.1
|
uses: aws-actions/configure-aws-credentials@v6.1.0
|
||||||
with:
|
with:
|
||||||
aws-region: us-east-2
|
aws-region: us-east-2
|
||||||
role-to-assume: arn:aws:iam::123456789100:role/my-github-actions-role
|
role-to-assume: arn:aws:iam::123456789100:role/my-github-actions-role
|
||||||
role-session-name: MySessionName
|
role-session-name: MySessionName
|
||||||
- name: Configure other AWS Credentials
|
- name: Configure other AWS Credentials
|
||||||
uses: aws-actions/configure-aws-credentials@v4.3.1
|
uses: aws-actions/configure-aws-credentials@v6.1.0
|
||||||
with:
|
with:
|
||||||
aws-region: us-east-2
|
aws-region: us-east-2
|
||||||
role-to-assume: arn:aws:iam::987654321000:role/my-second-role
|
role-to-assume: arn:aws:iam::987654321000:role/my-second-role
|
||||||
role-session-name: MySessionName
|
role-session-name: MySessionName
|
||||||
role-chaining: true
|
role-chaining: true
|
||||||
```
|
```
|
||||||
|
|
||||||
In this two-step example, the first step will use OIDC to assume the role
|
In this two-step example, the first step will use OIDC to assume the role
|
||||||
`arn:aws:iam::123456789100:role/my-github-actions-role` just as in the prior
|
`arn:aws:iam::123456789100:role/my-github-actions-role` just as in the prior
|
||||||
example. Following that, a second step will use this role to assume a different
|
example. Following that, a second step will use this role to assume a different
|
||||||
role, `arn:aws:iam::987654321000:role/my-second-role`.
|
role, `arn:aws:iam::987654321000:role/my-second-role`.
|
||||||
|
|
||||||
|
Note that the trust relationship/trust policy of the second role must grant the
|
||||||
|
permissions `sts:AssumeRole` and `sts:TagSession` to the first role. (Or,
|
||||||
|
alternatively, the `TagSession` permission can be omitted if you are using the
|
||||||
|
`role-skip-session-tagging: true` flag for the second step.)
|
||||||
|
|
||||||
### AssumeRole with static IAM credentials in repository secrets
|
### AssumeRole with static IAM credentials in repository secrets
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Configure AWS Credentials
|
- name: Configure AWS Credentials
|
||||||
uses: aws-actions/configure-aws-credentials@v4.3.1
|
uses: aws-actions/configure-aws-credentials@v6.1.0
|
||||||
with:
|
with:
|
||||||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||||
@@ -444,16 +734,18 @@ role, `arn:aws:iam::987654321000:role/my-second-role`.
|
|||||||
role-duration-seconds: 1200
|
role-duration-seconds: 1200
|
||||||
role-session-name: MySessionName
|
role-session-name: MySessionName
|
||||||
```
|
```
|
||||||
In this example, the secret `AWS_ROLE_TO_ASSUME` contains a string like
|
|
||||||
`arn:aws:iam::123456789100:role/my-github-actions-role`. To assume a role in
|
|
||||||
the same account as the static credentials, you can simply specify the role
|
|
||||||
name, like `role-to-assume: my-github-actions-role`.
|
|
||||||
|
|
||||||
### Retrieving credentials from step output, AssumeRole with temporary credentials
|
In this example, the secret `AWS_ROLE_TO_ASSUME` contains a string like
|
||||||
|
`arn:aws:iam::123456789100:role/my-github-actions-role`. To assume a role in the
|
||||||
|
same account as the static credentials, you can simply specify the role name,
|
||||||
|
like `role-to-assume: my-github-actions-role`.
|
||||||
|
|
||||||
|
### Retrieving credentials from step output
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Configure AWS Credentials 1
|
- name: Configure AWS Credentials 1
|
||||||
id: creds
|
id: creds
|
||||||
uses: aws-actions/configure-aws-credentials@v4.3.1
|
uses: aws-actions/configure-aws-credentials@v6.1.0
|
||||||
with:
|
with:
|
||||||
aws-region: us-east-2
|
aws-region: us-east-2
|
||||||
role-to-assume: arn:aws:iam::123456789100:role/my-github-actions-role
|
role-to-assume: arn:aws:iam::123456789100:role/my-github-actions-role
|
||||||
@@ -462,7 +754,7 @@ name, like `role-to-assume: my-github-actions-role`.
|
|||||||
run: |
|
run: |
|
||||||
aws sts get-caller-identity
|
aws sts get-caller-identity
|
||||||
- name: Configure AWS Credentials 2
|
- name: Configure AWS Credentials 2
|
||||||
uses: aws-actions/configure-aws-credentials@v4.3.1
|
uses: aws-actions/configure-aws-credentials@v6.1.0
|
||||||
with:
|
with:
|
||||||
aws-region: us-east-2
|
aws-region: us-east-2
|
||||||
aws-access-key-id: ${{ steps.creds.outputs.aws-access-key-id }}
|
aws-access-key-id: ${{ steps.creds.outputs.aws-access-key-id }}
|
||||||
@@ -473,18 +765,76 @@ name, like `role-to-assume: my-github-actions-role`.
|
|||||||
run: |
|
run: |
|
||||||
aws sts get-caller-identity
|
aws sts get-caller-identity
|
||||||
```
|
```
|
||||||
|
|
||||||
This example shows that you can reference the fetched credentials as outputs if
|
This example shows that you can reference the fetched credentials as outputs if
|
||||||
`output-credentials` is set to true. This example also shows that you can use
|
`output-credentials` is set to true. This example also shows that you can use
|
||||||
the `aws-session-token` input in a situation where session tokens are fetched
|
the `aws-session-token` input in a situation where session tokens are fetched
|
||||||
and passed to this action.
|
and passed to this action.
|
||||||
|
|
||||||
License
|
If you only want the credentials available as _step outputs_ and not exported to
|
||||||
-------
|
the environment (for example, on a self-hosted runner where you do not want the
|
||||||
|
assumed-role credentials to shadow an existing EC2 instance profile), pair
|
||||||
|
`output-credentials: true` with `output-env-credentials: false`. In that mode,
|
||||||
|
the action does not run its post-credential SDK-pickup validation step, since
|
||||||
|
the credentials were never written to the environment.
|
||||||
|
|
||||||
|
### Configure multiple AWS profiles in a single workflow
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- name: Configure AWS Credentials for Dev
|
||||||
|
uses: aws-actions/configure-aws-credentials@v6.1.0
|
||||||
|
with:
|
||||||
|
aws-region: us-east-1
|
||||||
|
role-to-assume: arn:aws:iam::111111111111:role/dev-role
|
||||||
|
aws-profile: dev
|
||||||
|
|
||||||
|
- name: Configure AWS Credentials for Prod
|
||||||
|
uses: aws-actions/configure-aws-credentials@v6.1.0
|
||||||
|
with:
|
||||||
|
aws-region: us-west-2
|
||||||
|
role-to-assume: arn:aws:iam::222222222222:role/prod-role
|
||||||
|
aws-profile: prod
|
||||||
|
|
||||||
|
- name: Use multiple profiles
|
||||||
|
run: |
|
||||||
|
# Check caller identity for dev account
|
||||||
|
aws sts get-caller-identity --profile dev
|
||||||
|
|
||||||
|
# Check caller identity for prod account
|
||||||
|
aws sts get-caller-identity --profile prod
|
||||||
|
|
||||||
|
# Deploy to dev using CDK
|
||||||
|
cdk deploy --profile dev
|
||||||
|
```
|
||||||
|
|
||||||
|
This example shows how to configure multiple named AWS profiles in a single
|
||||||
|
workflow. When using the `aws-profile` input, credentials are written to
|
||||||
|
`~/.aws/credentials` and `~/.aws/config` files, allowing you to reference
|
||||||
|
different profiles using the `--profile` flag with AWS CLI, SDKs, CDK, and other
|
||||||
|
tools.
|
||||||
|
|
||||||
|
Each profile is independent and can authenticate to different AWS accounts or
|
||||||
|
use different roles. This is particularly useful for multi-account deployments
|
||||||
|
or when you need to interact with multiple AWS environments in a single job.
|
||||||
|
|
||||||
|
## Versioning
|
||||||
|
|
||||||
|
Starting with version 5.0.0, this action uses semantic-style release tags and
|
||||||
|
[immutable releases][immutable-releases].
|
||||||
|
|
||||||
|
[immutable-releases]:
|
||||||
|
https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/immutable-releases
|
||||||
|
|
||||||
|
A floating version tag (vN) is also provided for convenience: this tag will move
|
||||||
|
to the latest major version (vN -> vN.2.1, vM -> vM.0.0, etc.).
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
This code is made available under the MIT license.
|
This code is made available under the MIT license.
|
||||||
|
|
||||||
Security Disclosures
|
## Security Disclosures
|
||||||
--------------------
|
|
||||||
If you would like to report a potential security issue in this project, please
|
If you would like to report a potential security issue in this project, please
|
||||||
do not create a GitHub issue. Instead, please follow the instructions
|
do not create a GitHub issue. Instead, please follow the instructions
|
||||||
[here](https://aws.amazon.com/security/vulnerability-reporting/) or
|
[on the vulnerability reporting page](https://aws.amazon.com/security/vulnerability-reporting/)
|
||||||
[email AWS security](mailto:aws-security@amazon.com) directly.
|
or [email AWS security](mailto:aws-security@amazon.com) directly.
|
||||||
|
|||||||
+1986
-10699
File diff suppressed because it is too large
Load Diff
+31
-3
@@ -1,10 +1,10 @@
|
|||||||
|
|
||||||
name: '"Configure AWS Credentials" Action for GitHub Actions'
|
name: '"Configure AWS Credentials" Action for GitHub Actions'
|
||||||
description: Configures AWS credentials for use in subsequent steps in a GitHub Action workflow
|
description: Configures AWS credentials for use in subsequent steps in a GitHub Action workflow
|
||||||
runs:
|
runs:
|
||||||
using: node20
|
using: node24
|
||||||
main: dist/index.js
|
main: dist/index.js
|
||||||
post: dist/cleanup/index.js
|
post: dist/cleanup/index.js
|
||||||
|
post-if: env.AWS_SKIP_CLEANUP_STEP != 'true'
|
||||||
branding:
|
branding:
|
||||||
color: orange
|
color: orange
|
||||||
icon: cloud
|
icon: cloud
|
||||||
@@ -12,6 +12,12 @@ inputs:
|
|||||||
aws-region:
|
aws-region:
|
||||||
description: AWS Region, e.g. us-east-2
|
description: AWS Region, e.g. us-east-2
|
||||||
required: true
|
required: true
|
||||||
|
aws-profile:
|
||||||
|
description: Name of the AWS profile to configure. When provided, credentials are written to ~/.aws/credentials and ~/.aws/config files instead of env variables (unless output-env-credentials is manually set to true). Name cannot contain whitespace, square brackets, or slashes.
|
||||||
|
required: false
|
||||||
|
overwrite-aws-profile:
|
||||||
|
description: Overwrite the given AWS profile if it already exists. Requires aws-profile. When set to false or not set, an error will be thrown if the profile already exists.
|
||||||
|
required: false
|
||||||
role-to-assume:
|
role-to-assume:
|
||||||
description: The Amazon Resource Name (ARN) of the role to assume. Use the provided credentials to assume an IAM role and configure the Actions environment with the assumed role credentials rather than with the provided credentials.
|
description: The Amazon Resource Name (ARN) of the role to assume. Use the provided credentials to assume an IAM role and configure the Actions environment with the assumed role credentials rather than with the provided credentials.
|
||||||
required: false
|
required: false
|
||||||
@@ -37,6 +43,9 @@ inputs:
|
|||||||
http-proxy:
|
http-proxy:
|
||||||
description: Proxy to use for the AWS SDK agent
|
description: Proxy to use for the AWS SDK agent
|
||||||
required: false
|
required: false
|
||||||
|
no-proxy:
|
||||||
|
description: Hosts to skip for the proxy configuration
|
||||||
|
required: false
|
||||||
mask-aws-account-id:
|
mask-aws-account-id:
|
||||||
description: Whether to mask the AWS account ID for these credentials as a secret value. By default the account ID will not be masked
|
description: Whether to mask the AWS account ID for these credentials as a secret value. By default the account ID will not be masked
|
||||||
required: false
|
required: false
|
||||||
@@ -52,6 +61,9 @@ inputs:
|
|||||||
role-skip-session-tagging:
|
role-skip-session-tagging:
|
||||||
description: Skip session tagging during role assumption
|
description: Skip session tagging during role assumption
|
||||||
required: false
|
required: false
|
||||||
|
transitive-tag-keys:
|
||||||
|
description: Define a list of transitive tag keys to pass when assuming a role
|
||||||
|
required: false
|
||||||
inline-session-policy:
|
inline-session-policy:
|
||||||
description: Define an inline session policy to use when assuming a role
|
description: Define an inline session policy to use when assuming a role
|
||||||
required: false
|
required: false
|
||||||
@@ -64,7 +76,6 @@ inputs:
|
|||||||
output-env-credentials:
|
output-env-credentials:
|
||||||
description: Whether to export credentials as environment variables. If you set this to false, you probably want to use output-credentials.
|
description: Whether to export credentials as environment variables. If you set this to false, you probably want to use output-credentials.
|
||||||
required: false
|
required: false
|
||||||
default: true
|
|
||||||
unset-current-credentials:
|
unset-current-credentials:
|
||||||
description: Whether to unset the existing credentials in your runner. May be useful if you run this action multiple times in the same job
|
description: Whether to unset the existing credentials in your runner. May be useful if you run this action multiple times in the same job
|
||||||
required: false
|
required: false
|
||||||
@@ -78,7 +89,24 @@ inputs:
|
|||||||
description: Some environments do not support special characters in AWS_SECRET_ACCESS_KEY. This option will retry fetching credentials until the secret access key does not contain special characters. This option overrides disable-retry and retry-max-attempts. This option is disabled by default
|
description: Some environments do not support special characters in AWS_SECRET_ACCESS_KEY. This option will retry fetching credentials until the secret access key does not contain special characters. This option overrides disable-retry and retry-max-attempts. This option is disabled by default
|
||||||
required: false
|
required: false
|
||||||
use-existing-credentials:
|
use-existing-credentials:
|
||||||
|
required: false
|
||||||
description: When enabled, this option will check if there are already valid credentials in the environment. If there are, new credentials will not be fetched. If there are not, the action will run as normal.
|
description: When enabled, this option will check if there are already valid credentials in the environment. If there are, new credentials will not be fetched. If there are not, the action will run as normal.
|
||||||
|
allowed-account-ids:
|
||||||
|
required: false
|
||||||
|
description: An option comma-delimited list of expected AWS account IDs. The action will fail if we receive credentials for the wrong account.
|
||||||
|
force-skip-oidc:
|
||||||
|
required: false
|
||||||
|
description: When enabled, this option will skip using GitHub OIDC provider even if the id-token permission is set. This is sometimes useful when using IAM instance credentials.
|
||||||
|
action-timeout-s:
|
||||||
|
required: false
|
||||||
|
description: A global timeout in seconds for the action. When the timeout is reached, the action immediately exits. The default is to run without a timeout.
|
||||||
|
custom-tags:
|
||||||
|
description: Additional tags to apply to the assumed role session. Must be a JSON object provided as a string.
|
||||||
|
required: false
|
||||||
|
sts-endpoint:
|
||||||
|
description: Custom STS endpoint URL. Use this to point to an STS-compatible API (e.g. MinIO, LocalStack) instead of the default AWS STS endpoint for the region.
|
||||||
|
required: false
|
||||||
|
|
||||||
outputs:
|
outputs:
|
||||||
aws-account-id:
|
aws-account-id:
|
||||||
description: The AWS account ID for the provided credentials
|
description: The AWS account ID for the provided credentials
|
||||||
|
|||||||
@@ -12,6 +12,10 @@
|
|||||||
"performance": {
|
"performance": {
|
||||||
"noDelete": "off"
|
"noDelete": "off"
|
||||||
},
|
},
|
||||||
|
"correctness": {
|
||||||
|
// Specifying a radix disables interpretation of 0x as a number (needed for backwards compat)
|
||||||
|
"useParseIntRadix": "off"
|
||||||
|
},
|
||||||
"complexity": {
|
"complexity": {
|
||||||
"noExtraBooleanCast": "off"
|
"noExtraBooleanCast": "off"
|
||||||
}
|
}
|
||||||
|
|||||||
+18869
-49867
File diff suppressed because one or more lines are too long
+73912
-50363
File diff suppressed because one or more lines are too long
+7
-2
@@ -2,8 +2,13 @@
|
|||||||
|
|
||||||
## [federated-setup](./federated-setup/README.md)
|
## [federated-setup](./federated-setup/README.md)
|
||||||
|
|
||||||
The directory contains templates for setting up the `configure-aws-credentials` federation between your GitHub Organization/repository and your AWS account.
|
The directory contains templates for setting up the `configure-aws-credentials`
|
||||||
|
federation between your GitHub Organization/repository and your AWS account.
|
||||||
|
|
||||||
## [cfn-deploy-example](./cfn-deploy-example/README.md)
|
## [cfn-deploy-example](./cfn-deploy-example/README.md)
|
||||||
|
|
||||||
Repository example uses aws-action `configure-aws-credentials` with OIDC federation template [github-actions-oidc-federation-and-role](./github-actions-oidc-federation-and-role.yml). Example demonstrates a repository that deploys AWS CloudFormation template using cfn-deploy GitHub Action.
|
Repository example uses aws-action `configure-aws-credentials` with OIDC
|
||||||
|
federation template
|
||||||
|
[github-actions-oidc-federation-and-role](./github-actions-oidc-federation-and-role.yml).
|
||||||
|
Example demonstrates a repository that deploys AWS CloudFormation template using
|
||||||
|
cfn-deploy GitHub Action.
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ jobs:
|
|||||||
sast-guard:
|
sast-guard:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: grolston/guard-action@main
|
- uses: grolston/guard-action@main
|
||||||
with:
|
with:
|
||||||
data_directory: './cloudformation/' ## change to your template directory
|
data_directory: './cloudformation/' ## change to your template directory
|
||||||
|
|||||||
@@ -18,9 +18,9 @@ jobs:
|
|||||||
contents: read
|
contents: read
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
- name: Configure AWS Credentials
|
- name: Configure AWS Credentials
|
||||||
uses: aws-actions/configure-aws-credentials@v4
|
uses: aws-actions/configure-aws-credentials@v6
|
||||||
with:
|
with:
|
||||||
aws-region: us-east-1
|
aws-region: us-east-1
|
||||||
## the following creates an ARN based on the values entered into github secrets
|
## the following creates an ARN based on the values entered into github secrets
|
||||||
|
|||||||
@@ -1,13 +1,23 @@
|
|||||||
# cfn-deploy example
|
# cfn-deploy example
|
||||||
|
|
||||||
Example uses aws-action `configure-aws-credentials` with OIDC federation. Prior to using this example project, the user needs to deploy the [github-actions-oidc-federation-and-role](../federated-setup/github-actions-oidc-federation-and-role.yml) template in the AWS account they want to deploy the CloudFormation template into. Specify the GitHub Organization name, repository name, and the specific branch you want to deploy on.
|
Example uses aws-action `configure-aws-credentials` with OIDC federation. Prior
|
||||||
|
to using this example project, the user needs to deploy the
|
||||||
|
[github-actions-oidc-federation-and-role](../federated-setup/github-actions-oidc-federation-and-role.yml)
|
||||||
|
template in the AWS account they want to deploy the CloudFormation template
|
||||||
|
into. Specify the GitHub Organization name, repository name, and the specific
|
||||||
|
branch you want to deploy on.
|
||||||
|
|
||||||
Within the [github/workflows](./.github/workflows/) directory there is a [compliance.yml](./.github/workflows/compliance.yml) and a [deploy.yml](./.github/workflows/deploy.yml). The deploy.yml file leverages the aws-action `configure-aws-credentials` and accesses GitHub Action Secrets for some of the variables. The compliance.yml runs static application security testing using cfn-guard.
|
Within the [github/workflows](./.github/workflows/) directory there is a
|
||||||
|
[compliance.yml](./.github/workflows/compliance.yml) and a
|
||||||
|
[deploy.yml](./.github/workflows/deploy.yml). The deploy.yml file leverages the
|
||||||
|
aws-action `configure-aws-credentials` and accesses GitHub Action Secrets for
|
||||||
|
some of the variables. The compliance.yml runs static application security
|
||||||
|
testing using cfn-guard.
|
||||||
|
|
||||||
To use the example you will need to set the following GitHub Action Secrets:
|
To use the example you will need to set the following GitHub Action Secrets:
|
||||||
|
|
||||||
| Secret Key | Used With | Description |
|
| Secret Key | Used With | Description |
|
||||||
| --------- | -------- | -----------|
|
| --------------- | -------------------------------- | ---------------------------------------- |
|
||||||
| AWS_ACCOUNT_ID | configure-aws-credentials | The AWS account ID |
|
| AWS_ACCOUNT_ID | configure-aws-credentials | The AWS account ID |
|
||||||
| AWS_DEPLOY_ROLE | configure-aws-credentials | The name of the IAM role |
|
| AWS_DEPLOY_ROLE | configure-aws-credentials | The name of the IAM role |
|
||||||
| VPC_ID | aws-cloudformation-github-deploy | VPC ID the EC2 Bastion is deployed to |
|
| VPC_ID | aws-cloudformation-github-deploy | VPC ID the EC2 Bastion is deployed to |
|
||||||
|
|||||||
@@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
## [github-action-oidc-federation](./github-actions-oidc-federation.yml)
|
## [github-action-oidc-federation](./github-actions-oidc-federation.yml)
|
||||||
|
|
||||||
Setup of the OIDC federation between your GitHub Organization/repository and your AWS account.
|
Setup of the OIDC federation between your GitHub Organization/repository and
|
||||||
|
your AWS account.
|
||||||
|
|
||||||
## [github-actions-oidc-federation-and-role](./github-actions-oidc-federation-and-role.yml)
|
## [github-actions-oidc-federation-and-role](./github-actions-oidc-federation-and-role.yml)
|
||||||
|
|
||||||
Setup of the OIDC federation between your GitHub Organization/repository and your AWS account along with a role that only executes on specific branch.
|
Setup of the OIDC federation between your GitHub Organization/repository and
|
||||||
|
your AWS account along with a role that only executes on specific branch.
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
/** @type {import('jest').Config} */
|
|
||||||
const config = {
|
|
||||||
verbose: true,
|
|
||||||
transform: {
|
|
||||||
'^.+\\.m?[tj]sx?$': ['ts-jest'],
|
|
||||||
},
|
|
||||||
testMatch: [
|
|
||||||
'<rootDir>/src/**/__tests__/**/*.ts?(x)',
|
|
||||||
'<rootDir>/(test|src)/**/*(*.)@(spec|test).ts?(x)',
|
|
||||||
'<rootDir>/test/**/*.(test|spec).(js|jsx|ts|tsx)',
|
|
||||||
],
|
|
||||||
clearMocks: true,
|
|
||||||
collectCoverage: true,
|
|
||||||
coverageReporters: ['json', 'lcov', 'clover', 'cobertura', 'text'],
|
|
||||||
coverageDirectory: 'coverage',
|
|
||||||
coveragePathIgnorePatterns: ['/node_modules/'],
|
|
||||||
testPathIgnorePatterns: ['/node_modules/'],
|
|
||||||
watchPathIgnorePatterns: ['/node_modules/'],
|
|
||||||
reporters: [
|
|
||||||
'default',
|
|
||||||
[
|
|
||||||
'jest-junit',
|
|
||||||
{
|
|
||||||
outputDirectory: 'test-reports',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
],
|
|
||||||
preset: 'ts-jest/presets/default-legacy',
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = config;
|
|
||||||
Generated
+5016
-3838
File diff suppressed because it is too large
Load Diff
+22
-21
@@ -1,14 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "configure-aws-credentials",
|
"name": "configure-aws-credentials",
|
||||||
"description": "A GitHub Action to configure AWS credentials",
|
"description": "A GitHub Action to configure AWS credentials",
|
||||||
"version": "4.3.1",
|
"version": "6.2.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"lint": "biome check --error-on-warnings ./src",
|
"lint": "biome check --error-on-warnings ./src ./test && markdownlint -i node_modules -i CHANGELOG.md '**/*.md'",
|
||||||
"lint:fix": "biome check --write ./src",
|
"lint:fix": "biome check --write ./src ./test && markdownlint -i node_modules -i CHANGELOG.md -f '**/*.md'",
|
||||||
"package": "npm run build && ncc build --license THIRD-PARTY -o dist && ncc build src/cleanup/index.ts -o dist/cleanup && cpy dist/THIRD-PARTY . && del-cli dist/THIRD-PARTY",
|
"package": "esbuild src/index.ts --bundle --platform=node --target=node24 --outfile=dist/index.js && esbuild src/cleanup/index.ts --bundle --platform=node --target=node24 --outfile=dist/cleanup/index.js && npm run license",
|
||||||
"test": "npm run lint && vitest run && npm run build",
|
"test": "npm run lint && vitest run && npm run build",
|
||||||
"clean": "del-cli coverage test-reports node_modules"
|
"clean": "del-cli coverage test-reports node_modules",
|
||||||
|
"license": "generate-license-file --config ./.generatelicensefile.json"
|
||||||
},
|
},
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Amazon.com, Inc. or its affiliates",
|
"name": "Amazon.com, Inc. or its affiliates",
|
||||||
@@ -16,26 +17,26 @@
|
|||||||
"organization": true
|
"organization": true
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@aws-sdk/credential-provider-env": "^3.858.0",
|
"@aws-sdk/credential-provider-env": "^3.972.39",
|
||||||
"@biomejs/biome": "2.1.3",
|
"@biomejs/biome": "2.4.15",
|
||||||
"@smithy/property-provider": "^4.0.3",
|
"@smithy/property-provider": "^4.3.4",
|
||||||
"@types/node": "^24.1.0",
|
"@types/node": "^25.9.1",
|
||||||
"@vercel/ncc": "^0.38.3",
|
"@vitest/coverage-v8": "4.1.5",
|
||||||
"@vitest/coverage-v8": "^3.2.4",
|
|
||||||
"aws-sdk-client-mock": "^4.1.0",
|
"aws-sdk-client-mock": "^4.1.0",
|
||||||
"cpy-cli": "^5.0.0",
|
"esbuild": "^0.28.0",
|
||||||
"del-cli": "^6.0.0",
|
"generate-license-file": "^4.1.1",
|
||||||
"json-schema": "^0.4.0",
|
"json-schema": "^0.4.0",
|
||||||
"memfs": "^4.25.1",
|
"markdownlint-cli": "^0.48.0",
|
||||||
|
"memfs": "^4.57.2",
|
||||||
"standard-version": "^9.5.0",
|
"standard-version": "^9.5.0",
|
||||||
"typescript": "^5.8.3",
|
"typescript": "^6.0.3",
|
||||||
"vitest": "^3.2.4"
|
"vitest": "4.1.5"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.11.1",
|
"@actions/core": "^3.0.1",
|
||||||
"@aws-sdk/client-sts": "^3.858.0",
|
"@aws-sdk/client-sts": "^3.1049.0",
|
||||||
"@smithy/node-http-handler": "^4.1.0",
|
"@smithy/node-http-handler": "^4.7.3",
|
||||||
"https-proxy-agent": "^7.0.6"
|
"proxy-agent": "^8.0.1"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"aws",
|
"aws",
|
||||||
@@ -43,7 +44,7 @@
|
|||||||
"github-action"
|
"github-action"
|
||||||
],
|
],
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 14.0.0"
|
"node": ">= 16.3.0"
|
||||||
},
|
},
|
||||||
"main": "build/index.js",
|
"main": "build/index.js",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
"bump-minor-pre-major": false,
|
"bump-minor-pre-major": false,
|
||||||
"bump-patch-for-minor-pre-major": false,
|
"bump-patch-for-minor-pre-major": false,
|
||||||
"draft": false,
|
"draft": false,
|
||||||
"prerelease": false
|
"prerelease": false,
|
||||||
|
"exclude-paths": [".github", "dist"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json"
|
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json"
|
||||||
|
|||||||
+56
-15
@@ -2,45 +2,72 @@ import { info } from '@actions/core';
|
|||||||
import { STSClient } from '@aws-sdk/client-sts';
|
import { STSClient } from '@aws-sdk/client-sts';
|
||||||
import type { AwsCredentialIdentity } from '@aws-sdk/types';
|
import type { AwsCredentialIdentity } from '@aws-sdk/types';
|
||||||
import { NodeHttpHandler } from '@smithy/node-http-handler';
|
import { NodeHttpHandler } from '@smithy/node-http-handler';
|
||||||
import { HttpsProxyAgent } from 'https-proxy-agent';
|
import { ProxyAgent } from 'proxy-agent';
|
||||||
import { errorMessage } from './helpers';
|
import { buildCustomUserAgent, errorMessage, getCallerIdentity } from './helpers';
|
||||||
|
import { ProxyResolver } from './ProxyResolver';
|
||||||
|
|
||||||
const USER_AGENT = 'configure-aws-credentials-for-github-actions';
|
if (!process.env.AWS_EXECUTION_ENV) {
|
||||||
|
process.env.AWS_EXECUTION_ENV = 'GitHubActions';
|
||||||
|
}
|
||||||
|
|
||||||
export interface CredentialsClientProps {
|
export interface CredentialsClientProps {
|
||||||
region?: string;
|
region?: string;
|
||||||
proxyServer?: string;
|
proxyServer?: string;
|
||||||
|
noProxy?: string;
|
||||||
|
stsEndpoint?: string;
|
||||||
|
roleChaining: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CredentialsClient {
|
export class CredentialsClient {
|
||||||
public region?: string;
|
public region?: string;
|
||||||
private _stsClient?: STSClient;
|
private _stsClient?: STSClient;
|
||||||
private readonly requestHandler?: NodeHttpHandler;
|
private readonly requestHandler?: NodeHttpHandler;
|
||||||
|
private readonly stsEndpoint?: string;
|
||||||
|
private roleChaining?: boolean;
|
||||||
|
|
||||||
constructor(props: CredentialsClientProps) {
|
constructor(props: CredentialsClientProps) {
|
||||||
|
if (props.region !== undefined) {
|
||||||
this.region = props.region;
|
this.region = props.region;
|
||||||
|
}
|
||||||
if (props.proxyServer) {
|
if (props.proxyServer) {
|
||||||
info('Configuring proxy handler for STS client');
|
info('Configuring proxy handler for STS client');
|
||||||
const handler = new HttpsProxyAgent(props.proxyServer);
|
const proxyOptions: { httpProxy: string; httpsProxy: string; noProxy?: string } = {
|
||||||
|
httpProxy: props.proxyServer,
|
||||||
|
httpsProxy: props.proxyServer,
|
||||||
|
};
|
||||||
|
if (props.noProxy !== undefined) {
|
||||||
|
proxyOptions.noProxy = props.noProxy;
|
||||||
|
}
|
||||||
|
const getProxyForUrl = new ProxyResolver(proxyOptions).getProxyForUrl;
|
||||||
|
const handler = new ProxyAgent({ getProxyForUrl });
|
||||||
this.requestHandler = new NodeHttpHandler({
|
this.requestHandler = new NodeHttpHandler({
|
||||||
httpAgent: handler,
|
|
||||||
httpsAgent: handler,
|
httpsAgent: handler,
|
||||||
|
httpAgent: handler,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (props.stsEndpoint) {
|
||||||
|
this.stsEndpoint = props.stsEndpoint;
|
||||||
|
}
|
||||||
|
this.roleChaining = props.roleChaining;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get stsClient(): STSClient {
|
public get stsClient(): STSClient {
|
||||||
if (!this._stsClient) {
|
if (!this._stsClient || this.roleChaining) {
|
||||||
this._stsClient = new STSClient({
|
this._stsClient = new STSClient({
|
||||||
region: this.region,
|
customUserAgent: buildCustomUserAgent(),
|
||||||
customUserAgent: USER_AGENT,
|
...(this.region !== undefined && { region: this.region }),
|
||||||
requestHandler: this.requestHandler ? this.requestHandler : undefined,
|
...(this.stsEndpoint !== undefined && { endpoint: this.stsEndpoint }),
|
||||||
|
...(this.requestHandler !== undefined && { requestHandler: this.requestHandler }),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return this._stsClient;
|
return this._stsClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async validateCredentials(expectedAccessKeyId?: string, roleChaining?: boolean) {
|
public async validateCredentials(
|
||||||
|
expectedAccessKeyId?: string,
|
||||||
|
roleChaining?: boolean,
|
||||||
|
expectedAccountIds?: string[],
|
||||||
|
) {
|
||||||
let credentials: AwsCredentialIdentity;
|
let credentials: AwsCredentialIdentity;
|
||||||
try {
|
try {
|
||||||
credentials = await this.loadCredentials();
|
credentials = await this.loadCredentials();
|
||||||
@@ -50,22 +77,36 @@ export class CredentialsClient {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(`Credentials could not be loaded, please check your action inputs: ${errorMessage(error)}`);
|
throw new Error(`Credentials could not be loaded, please check your action inputs: ${errorMessage(error)}`);
|
||||||
}
|
}
|
||||||
|
if (expectedAccountIds && expectedAccountIds.length > 0 && expectedAccountIds[0] !== '') {
|
||||||
|
let callerIdentity: Awaited<ReturnType<typeof getCallerIdentity>>;
|
||||||
|
try {
|
||||||
|
callerIdentity = await getCallerIdentity(this.stsClient);
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(`Could not validate account ID of credentials: ${errorMessage(error)}`);
|
||||||
|
}
|
||||||
|
if (!callerIdentity.Account || !expectedAccountIds.includes(callerIdentity.Account)) {
|
||||||
|
throw new Error(
|
||||||
|
`The account ID of the provided credentials (${
|
||||||
|
callerIdentity.Account ?? 'unknown'
|
||||||
|
}) does not match any of the expected account IDs: ${expectedAccountIds.join(', ')}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!roleChaining) {
|
if (!roleChaining) {
|
||||||
const actualAccessKeyId = credentials.accessKeyId;
|
const actualAccessKeyId = credentials.accessKeyId;
|
||||||
|
|
||||||
if (expectedAccessKeyId && expectedAccessKeyId !== actualAccessKeyId) {
|
if (expectedAccessKeyId && expectedAccessKeyId !== actualAccessKeyId) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'Unexpected failure: Credentials loaded by the SDK do not match the access key ID configured by the action',
|
'Credentials loaded by the SDK do not match the expected access key ID configured by the action',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async loadCredentials() {
|
private async loadCredentials() {
|
||||||
const client = new STSClient({
|
const config = {} as { requestHandler?: NodeHttpHandler };
|
||||||
requestHandler: this.requestHandler ? this.requestHandler : undefined,
|
if (this.requestHandler !== undefined) config.requestHandler = this.requestHandler;
|
||||||
});
|
const client = new STSClient(config);
|
||||||
return client.config.credentials();
|
return client.config.credentials();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
// Based on https://github.com/Rob--W/proxy-from-env/tree/caf8c32301afdac8b5feaf346028bd8240690144
|
||||||
|
// See https://github.com/Rob--W/proxy-from-env/blob/caf8c32301afdac8b5feaf346028bd8240690144/LICENSE
|
||||||
|
import type * as http from 'node:http';
|
||||||
|
|
||||||
|
const DEFAULT_PORTS: Record<string, number> = {
|
||||||
|
http: 80,
|
||||||
|
https: 443,
|
||||||
|
};
|
||||||
|
export interface ProxyOptions {
|
||||||
|
readonly noProxy?: string;
|
||||||
|
readonly httpsProxy?: string;
|
||||||
|
readonly httpProxy?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ProxyResolver {
|
||||||
|
options: ProxyOptions;
|
||||||
|
constructor(options: ProxyOptions) {
|
||||||
|
this.options = options;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This method matches the interface expected by 'proxy-agent'. It is an arrow function to bind 'this'.
|
||||||
|
public readonly getProxyForUrl = (url: string, _req: http.ClientRequest): string => {
|
||||||
|
return this.getProxyForUrlOptions(url, this.options);
|
||||||
|
};
|
||||||
|
|
||||||
|
private getProxyForUrlOptions(url: string | URL, options?: ProxyOptions): string {
|
||||||
|
let parsedUrl: URL;
|
||||||
|
try {
|
||||||
|
parsedUrl = typeof url === 'string' ? new URL(url) : url;
|
||||||
|
} catch (_) {
|
||||||
|
return ''; // Don't proxy invalid URLs.
|
||||||
|
}
|
||||||
|
const proto = parsedUrl.protocol.split(':', 1)[0];
|
||||||
|
if (!proto) return ''; // Don't proxy URLs without a protocol.
|
||||||
|
const hostname = parsedUrl.host;
|
||||||
|
const port = parseInt(parsedUrl.port || '') || DEFAULT_PORTS[proto] || 0;
|
||||||
|
|
||||||
|
if (options?.noProxy && !this.shouldProxy(hostname, port, options.noProxy)) return '';
|
||||||
|
if (proto === 'http' && options?.httpProxy) return options.httpProxy;
|
||||||
|
if (proto === 'https' && options?.httpsProxy) return options.httpsProxy;
|
||||||
|
return ''; // No proxy configured for this protocol or unknown protocol
|
||||||
|
}
|
||||||
|
|
||||||
|
private shouldProxy(hostname: string, port: number, noProxy: string): boolean {
|
||||||
|
if (!noProxy) return true;
|
||||||
|
if (noProxy === '*') return false; // Never proxy if wildcard is set.
|
||||||
|
|
||||||
|
return noProxy.split(/[,\s]/).every((proxy) => {
|
||||||
|
if (!proxy) return true; // Skip zero-length hosts.
|
||||||
|
|
||||||
|
const parsedProxy = proxy.match(/^(.+):(\d+)$/);
|
||||||
|
const parsedProxyHostname = parsedProxy ? parsedProxy[1] : proxy;
|
||||||
|
const parsedProxyPort = parsedProxy?.[2] ? parseInt(parsedProxy[2]) : 0;
|
||||||
|
|
||||||
|
if (parsedProxyPort && parsedProxyPort !== port) return true; // Skip if ports don't match.
|
||||||
|
|
||||||
|
if (parsedProxyHostname && !/^[.*]/.test(parsedProxyHostname)) {
|
||||||
|
// No wildcards, so stop proxying if there is an exact match.
|
||||||
|
return hostname !== parsedProxyHostname;
|
||||||
|
}
|
||||||
|
|
||||||
|
let cleanProxyHostname = parsedProxyHostname;
|
||||||
|
if (parsedProxyHostname && parsedProxyHostname.charAt(0) === '*') {
|
||||||
|
// Remove leading wildcard.
|
||||||
|
cleanProxyHostname = parsedProxyHostname.slice(1);
|
||||||
|
}
|
||||||
|
// Stop proxying if the hostname ends with the no_proxy host.
|
||||||
|
return !cleanProxyHostname || !hostname.endsWith(cleanProxyHostname);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
+145
-21
@@ -1,14 +1,18 @@
|
|||||||
import assert from 'node:assert';
|
import assert from 'node:assert';
|
||||||
import fs from 'node:fs';
|
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import type { AssumeRoleCommandInput, STSClient, Tag } from '@aws-sdk/client-sts';
|
import type { AssumeRoleCommandInput, STSClient, Tag } from '@aws-sdk/client-sts';
|
||||||
import { AssumeRoleCommand, AssumeRoleWithWebIdentityCommand } from '@aws-sdk/client-sts';
|
import {
|
||||||
|
AssumeRoleCommand,
|
||||||
|
AssumeRoleWithWebIdentityCommand,
|
||||||
|
PackedPolicyTooLargeException,
|
||||||
|
} from '@aws-sdk/client-sts';
|
||||||
import type { CredentialsClient } from './CredentialsClient';
|
import type { CredentialsClient } from './CredentialsClient';
|
||||||
import { errorMessage, isDefined, sanitizeGitHubVariables } from './helpers';
|
import { errorMessage, isDefined, readFileUtf8, sanitizeGitHubVariables } from './helpers';
|
||||||
|
|
||||||
async function assumeRoleWithOIDC(params: AssumeRoleCommandInput, client: STSClient, webIdentityToken: string) {
|
async function assumeRoleWithOIDC(params: AssumeRoleCommandInput, client: STSClient, webIdentityToken: string) {
|
||||||
delete params.Tags;
|
delete params.Tags;
|
||||||
|
delete params.TransitiveTagKeys;
|
||||||
core.info('Assuming role with OIDC');
|
core.info('Assuming role with OIDC');
|
||||||
try {
|
try {
|
||||||
const creds = await client.send(
|
const creds = await client.send(
|
||||||
@@ -35,13 +39,14 @@ async function assumeRoleWithWebIdentityTokenFile(
|
|||||||
const webIdentityTokenFilePath = path.isAbsolute(webIdentityTokenFile)
|
const webIdentityTokenFilePath = path.isAbsolute(webIdentityTokenFile)
|
||||||
? webIdentityTokenFile
|
? webIdentityTokenFile
|
||||||
: path.join(workspace, webIdentityTokenFile);
|
: path.join(workspace, webIdentityTokenFile);
|
||||||
if (!fs.existsSync(webIdentityTokenFilePath)) {
|
const webIdentityToken = readFileUtf8(webIdentityTokenFilePath);
|
||||||
|
if (webIdentityToken === null) {
|
||||||
throw new Error(`Web identity token file does not exist: ${webIdentityTokenFilePath}`);
|
throw new Error(`Web identity token file does not exist: ${webIdentityTokenFilePath}`);
|
||||||
}
|
}
|
||||||
core.info('Assuming role with web identity token file');
|
core.info('Assuming role with web identity token file');
|
||||||
try {
|
try {
|
||||||
const webIdentityToken = fs.readFileSync(webIdentityTokenFilePath, 'utf8');
|
|
||||||
delete params.Tags;
|
delete params.Tags;
|
||||||
|
delete params.TransitiveTagKeys;
|
||||||
const creds = await client.send(
|
const creds = await client.send(
|
||||||
new AssumeRoleWithWebIdentityCommand({
|
new AssumeRoleWithWebIdentityCommand({
|
||||||
...params,
|
...params,
|
||||||
@@ -60,6 +65,13 @@ async function assumeRoleWithCredentials(params: AssumeRoleCommandInput, client:
|
|||||||
const creds = await client.send(new AssumeRoleCommand({ ...params }));
|
const creds = await client.send(new AssumeRoleCommand({ ...params }));
|
||||||
return creds;
|
return creds;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
if (error instanceof PackedPolicyTooLargeException) {
|
||||||
|
core.info('Session tag size is too large; dropping droppable tags and retrying.');
|
||||||
|
const droppableKeys = new Set(DROPPABLE_TAG_SOURCES.map((s) => s.key));
|
||||||
|
params.Tags = params.Tags?.filter((tag) => !droppableKeys.has(tag.Key ?? ''));
|
||||||
|
const creds = await client.send(new AssumeRoleCommand({ ...params }));
|
||||||
|
return creds;
|
||||||
|
}
|
||||||
throw new Error(`Could not assume role with user credentials: ${errorMessage(error)}`);
|
throw new Error(`Could not assume role with user credentials: ${errorMessage(error)}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,12 +82,106 @@ export interface assumeRoleParams {
|
|||||||
roleDuration: number;
|
roleDuration: number;
|
||||||
roleSessionName: string;
|
roleSessionName: string;
|
||||||
roleSkipSessionTagging?: boolean;
|
roleSkipSessionTagging?: boolean;
|
||||||
|
transitiveTagKeys?: string[];
|
||||||
sourceAccountId?: string;
|
sourceAccountId?: string;
|
||||||
roleExternalId?: string;
|
roleExternalId?: string;
|
||||||
webIdentityTokenFile?: string;
|
webIdentityTokenFile?: string;
|
||||||
webIdentityToken?: string;
|
webIdentityToken?: string;
|
||||||
inlineSessionPolicy?: string;
|
inlineSessionPolicy?: string;
|
||||||
managedSessionPolicies?: { arn: string }[];
|
managedSessionPolicies?: { arn: string }[];
|
||||||
|
customTags?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const TAG_KEY_REGEX = /^[\p{L}\p{Z}\p{N}_.:/=+\-@]+$/u;
|
||||||
|
const TAG_VALUE_REGEX = /^[\p{L}\p{Z}\p{N}_.:/=+\-@]*$/u;
|
||||||
|
const MAX_TAG_KEY_LENGTH = 128;
|
||||||
|
const MAX_TAG_VALUE_LENGTH = 256;
|
||||||
|
const MAX_SESSION_TAGS = 50;
|
||||||
|
|
||||||
|
// Identity/audit primitives. Always emitted and cannot be dropped.
|
||||||
|
const NON_DROPPABLE_TAG_SOURCES: ReadonlyArray<{ key: string; envVar: string }> = [
|
||||||
|
{ key: 'Repository', envVar: 'GITHUB_REPOSITORY' },
|
||||||
|
{ key: 'Workflow', envVar: 'GITHUB_WORKFLOW' },
|
||||||
|
{ key: 'Action', envVar: 'GITHUB_ACTION' },
|
||||||
|
{ key: 'Actor', envVar: 'GITHUB_ACTOR' },
|
||||||
|
{ key: 'Commit', envVar: 'GITHUB_SHA' },
|
||||||
|
{ key: 'Branch', envVar: 'GITHUB_REF' },
|
||||||
|
];
|
||||||
|
|
||||||
|
// Convenience metadata. If the AssumeRole call fails due to compressed size of
|
||||||
|
// session tags being too large, we will drop these tags and retry once.
|
||||||
|
const DROPPABLE_TAG_SOURCES: ReadonlyArray<{ key: string; envVar: string }> = [
|
||||||
|
{ key: 'EventName', envVar: 'GITHUB_EVENT_NAME' },
|
||||||
|
{ key: 'BaseRef', envVar: 'GITHUB_BASE_REF' },
|
||||||
|
{ key: 'HeadRef', envVar: 'GITHUB_HEAD_REF' },
|
||||||
|
{ key: 'RunId', envVar: 'GITHUB_RUN_ID' },
|
||||||
|
{ key: 'Job', envVar: 'GITHUB_JOB' },
|
||||||
|
{ key: 'TriggeringActor', envVar: 'GITHUB_TRIGGERING_ACTOR' },
|
||||||
|
];
|
||||||
|
|
||||||
|
const PROTECTED_TAG_KEYS = new Set<string>([
|
||||||
|
'GitHub',
|
||||||
|
...NON_DROPPABLE_TAG_SOURCES.map((s) => s.key),
|
||||||
|
...DROPPABLE_TAG_SOURCES.map((s) => s.key),
|
||||||
|
]);
|
||||||
|
|
||||||
|
export function parseAndValidateCustomTags(customTags: string, existingTags: Tag[]): Tag[] {
|
||||||
|
let parsed: unknown;
|
||||||
|
try {
|
||||||
|
parsed = JSON.parse(customTags);
|
||||||
|
} catch {
|
||||||
|
throw new Error('custom-tags: input is not valid JSON');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
||||||
|
throw new Error('custom-tags: input must be a JSON object (not an array or primitive)');
|
||||||
|
}
|
||||||
|
|
||||||
|
const newTags: Tag[] = [];
|
||||||
|
|
||||||
|
for (const [key, value] of Object.entries(parsed)) {
|
||||||
|
if (typeof value === 'object') {
|
||||||
|
throw new Error(
|
||||||
|
`custom-tags: value for key '${key}' must be a string, number, or boolean (not an object or array)`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const stringValue = String(value);
|
||||||
|
|
||||||
|
if (key.length === 0 || key.length > MAX_TAG_KEY_LENGTH) {
|
||||||
|
throw new Error(`custom-tags: key '${key}' must be between 1 and ${MAX_TAG_KEY_LENGTH} characters`);
|
||||||
|
}
|
||||||
|
if (stringValue.length > MAX_TAG_VALUE_LENGTH) {
|
||||||
|
throw new Error(
|
||||||
|
`custom-tags: value for key '${key}' exceeds maximum length of ${MAX_TAG_VALUE_LENGTH} characters`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (!TAG_KEY_REGEX.test(key)) {
|
||||||
|
throw new Error(
|
||||||
|
`custom-tags: key '${key}' contains invalid characters. Allowed: unicode letters, digits, spaces, and _.:/=+-@`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (stringValue.length > 0 && !TAG_VALUE_REGEX.test(stringValue)) {
|
||||||
|
throw new Error(
|
||||||
|
`custom-tags: value for key '${key}' contains invalid characters. Allowed: unicode letters, digits, spaces, and _.:/=+-@`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (PROTECTED_TAG_KEYS.has(key)) {
|
||||||
|
throw new Error(
|
||||||
|
`custom-tags: key '${key}' conflicts with a protected session tag set by this action and cannot be overridden`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
newTags.push({ Key: key, Value: stringValue });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (existingTags.length + newTags.length > MAX_SESSION_TAGS) {
|
||||||
|
throw new Error(
|
||||||
|
`custom-tags: total session tags (${existingTags.length + newTags.length}) would exceed the AWS limit of ${MAX_SESSION_TAGS}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return newTags;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function assumeRole(params: assumeRoleParams) {
|
export async function assumeRole(params: assumeRoleParams) {
|
||||||
@@ -87,10 +193,12 @@ export async function assumeRole(params: assumeRoleParams) {
|
|||||||
roleDuration,
|
roleDuration,
|
||||||
roleSessionName,
|
roleSessionName,
|
||||||
roleSkipSessionTagging,
|
roleSkipSessionTagging,
|
||||||
|
transitiveTagKeys,
|
||||||
webIdentityTokenFile,
|
webIdentityTokenFile,
|
||||||
webIdentityToken,
|
webIdentityToken,
|
||||||
inlineSessionPolicy,
|
inlineSessionPolicy,
|
||||||
managedSessionPolicies,
|
managedSessionPolicies,
|
||||||
|
customTags,
|
||||||
} = { ...params };
|
} = { ...params };
|
||||||
|
|
||||||
// Load GitHub environment variables
|
// Load GitHub environment variables
|
||||||
@@ -99,28 +207,39 @@ export async function assumeRole(params: assumeRoleParams) {
|
|||||||
throw new Error('Missing required environment variables. Are you running in GitHub Actions?');
|
throw new Error('Missing required environment variables. Are you running in GitHub Actions?');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load role session tags
|
// Build session tags. Values are sanitized because the AWS tag value spec is more
|
||||||
const tagArray: Tag[] = [
|
// restrictive than permissible characters in environment variables.
|
||||||
{ Key: 'GitHub', Value: 'Actions' },
|
const protectedTags: Tag[] = [{ Key: 'GitHub', Value: 'Actions' }];
|
||||||
{ Key: 'Repository', Value: GITHUB_REPOSITORY },
|
for (const { key, envVar } of NON_DROPPABLE_TAG_SOURCES) {
|
||||||
{ Key: 'Workflow', Value: sanitizeGitHubVariables(GITHUB_WORKFLOW) },
|
const value = process.env[envVar];
|
||||||
{ Key: 'Action', Value: GITHUB_ACTION },
|
if (value) {
|
||||||
{ Key: 'Actor', Value: sanitizeGitHubVariables(GITHUB_ACTOR) },
|
protectedTags.push({ Key: key, Value: sanitizeGitHubVariables(value) });
|
||||||
{ Key: 'Commit', Value: GITHUB_SHA },
|
|
||||||
];
|
|
||||||
if (process.env.GITHUB_REF) {
|
|
||||||
tagArray.push({
|
|
||||||
Key: 'Branch',
|
|
||||||
Value: sanitizeGitHubVariables(process.env.GITHUB_REF),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
for (const { key, envVar } of DROPPABLE_TAG_SOURCES) {
|
||||||
|
const value = process.env[envVar];
|
||||||
|
if (value) {
|
||||||
|
protectedTags.push({ Key: key, Value: sanitizeGitHubVariables(value) });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsedCustomTags: Tag[] = customTags ? parseAndValidateCustomTags(customTags, protectedTags) : [];
|
||||||
|
|
||||||
|
const tagArray: Tag[] = [...protectedTags, ...parsedCustomTags];
|
||||||
|
|
||||||
const tags = roleSkipSessionTagging ? undefined : tagArray;
|
const tags = roleSkipSessionTagging ? undefined : tagArray;
|
||||||
if (!tags) {
|
if (!tags) {
|
||||||
core.debug('Role session tagging has been skipped.');
|
core.debug('Role session tagging has been skipped.');
|
||||||
} else {
|
} else {
|
||||||
core.debug(`${tags.length} role session tags are being used.`);
|
core.debug(`${tags.length} role session tags are being used:`);
|
||||||
|
core.debug(JSON.stringify(tagArray));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//only populate transitiveTagKeys array if user is actually using session tagging
|
||||||
|
const transitiveTagKeysArray = roleSkipSessionTagging
|
||||||
|
? undefined
|
||||||
|
: transitiveTagKeys?.filter((key) => tags?.some((tag) => tag.Key === key));
|
||||||
|
|
||||||
// Calculate role ARN from name and account ID (currently only supports `aws` partition)
|
// Calculate role ARN from name and account ID (currently only supports `aws` partition)
|
||||||
let roleArn = roleToAssume;
|
let roleArn = roleToAssume;
|
||||||
if (!roleArn.startsWith('arn:aws')) {
|
if (!roleArn.startsWith('arn:aws')) {
|
||||||
@@ -137,12 +256,17 @@ export async function assumeRole(params: assumeRoleParams) {
|
|||||||
RoleSessionName: roleSessionName,
|
RoleSessionName: roleSessionName,
|
||||||
DurationSeconds: roleDuration,
|
DurationSeconds: roleDuration,
|
||||||
Tags: tags ? tags : undefined,
|
Tags: tags ? tags : undefined,
|
||||||
|
TransitiveTagKeys: transitiveTagKeysArray ? transitiveTagKeysArray : undefined,
|
||||||
ExternalId: roleExternalId ? roleExternalId : undefined,
|
ExternalId: roleExternalId ? roleExternalId : undefined,
|
||||||
Policy: inlineSessionPolicy ? inlineSessionPolicy : undefined,
|
Policy: inlineSessionPolicy ? inlineSessionPolicy : undefined,
|
||||||
PolicyArns: managedSessionPolicies?.length ? managedSessionPolicies : undefined,
|
PolicyArns: managedSessionPolicies?.length ? managedSessionPolicies : undefined,
|
||||||
};
|
};
|
||||||
const keys = Object.keys(commonAssumeRoleParams) as Array<keyof typeof commonAssumeRoleParams>;
|
const keys = Object.keys(commonAssumeRoleParams) as Array<keyof typeof commonAssumeRoleParams>;
|
||||||
keys.forEach((k) => commonAssumeRoleParams[k] === undefined && delete commonAssumeRoleParams[k]);
|
keys.forEach((k) => {
|
||||||
|
if (commonAssumeRoleParams[k] === undefined) {
|
||||||
|
delete commonAssumeRoleParams[k];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Instantiate STS client
|
// Instantiate STS client
|
||||||
const stsClient = credentialsClient.stsClient;
|
const stsClient = credentialsClient.stsClient;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import { errorMessage } from '../helpers';
|
import { errorMessage, getBooleanInput } from '../helpers';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When the GitHub Actions job is done, clean up any environment variables that
|
* When the GitHub Actions job is done, clean up any environment variables that
|
||||||
@@ -13,8 +13,9 @@ import { errorMessage } from '../helpers';
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export function cleanup() {
|
export function cleanup() {
|
||||||
const outputEnvCredentialsInput = core.getInput('output-env-credentials', { required: false }) || 'true';
|
// Only attempt to change environment variables if we changed them in the first place
|
||||||
if (outputEnvCredentialsInput === 'true') {
|
const awsProfile = core.getInput('aws-profile', { required: false });
|
||||||
|
if (getBooleanInput('output-env-credentials', { required: false, default: !awsProfile })) {
|
||||||
try {
|
try {
|
||||||
// The GitHub Actions toolkit does not have an option to completely unset
|
// The GitHub Actions toolkit does not have an option to completely unset
|
||||||
// environment variables, so we overwrite the current value with an empty
|
// environment variables, so we overwrite the current value with an empty
|
||||||
@@ -25,11 +26,15 @@ export function cleanup() {
|
|||||||
core.exportVariable('AWS_SESSION_TOKEN', '');
|
core.exportVariable('AWS_SESSION_TOKEN', '');
|
||||||
core.exportVariable('AWS_DEFAULT_REGION', '');
|
core.exportVariable('AWS_DEFAULT_REGION', '');
|
||||||
core.exportVariable('AWS_REGION', '');
|
core.exportVariable('AWS_REGION', '');
|
||||||
|
if (core.getInput('aws-profile')) {
|
||||||
|
core.exportVariable('AWS_PROFILE', '');
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(errorMessage(error));
|
core.setFailed(errorMessage(error));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* c8 ignore start */
|
/* c8 ignore start */
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
+193
-11
@@ -1,11 +1,34 @@
|
|||||||
|
import * as fs from 'node:fs';
|
||||||
|
import * as path from 'node:path';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import type { Credentials } from '@aws-sdk/client-sts';
|
import type { Credentials, STSClient } from '@aws-sdk/client-sts';
|
||||||
import { GetCallerIdentityCommand } from '@aws-sdk/client-sts';
|
import { GetCallerIdentityCommand } from '@aws-sdk/client-sts';
|
||||||
|
import type { UserAgent } from '@smithy/types';
|
||||||
import type { CredentialsClient } from './CredentialsClient';
|
import type { CredentialsClient } from './CredentialsClient';
|
||||||
|
|
||||||
const MAX_TAG_VALUE_LENGTH = 256;
|
const MAX_TAG_VALUE_LENGTH = 256;
|
||||||
const SANITIZATION_CHARACTER = '_';
|
const SANITIZATION_CHARACTER = '_';
|
||||||
const SPECIAL_CHARS_REGEX = /[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]+/;
|
const SPECIAL_CHARS_REGEX = /[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]+/;
|
||||||
|
const USER_AGENT_PREFIX = 'configure-aws-credentials-for-github-actions';
|
||||||
|
const UA_FIELDS: ReadonlyArray<{ env: string; label: string; pattern: RegExp }> = [
|
||||||
|
{ env: 'GITHUB_ACTION', label: 'action', pattern: /^[A-Za-z0-9_-]{1,128}$/ },
|
||||||
|
{ env: 'GITHUB_RUN_ID', label: 'run_id', pattern: /^[0-9]{1,20}$/ },
|
||||||
|
{ env: 'GITHUB_RUN_ATTEMPT', label: 'attempt', pattern: /^[0-9]{1,10}$/ },
|
||||||
|
];
|
||||||
|
|
||||||
|
export function buildCustomUserAgent(): UserAgent {
|
||||||
|
const tokens: UserAgent = [[USER_AGENT_PREFIX]];
|
||||||
|
for (const { env, label, pattern } of UA_FIELDS) {
|
||||||
|
const value = process.env[env];
|
||||||
|
if (value === undefined) continue;
|
||||||
|
if (pattern.test(value)) {
|
||||||
|
tokens.push(['md', `${label}#${value}`]);
|
||||||
|
} else {
|
||||||
|
core.warning(`${env} has unexpected format; omitting from User-Agent`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tokens;
|
||||||
|
}
|
||||||
|
|
||||||
export function translateEnvVariables() {
|
export function translateEnvVariables() {
|
||||||
const envVars = [
|
const envVars = [
|
||||||
@@ -20,6 +43,7 @@ export function translateEnvVariables() {
|
|||||||
'ROLE_EXTERNAL_ID',
|
'ROLE_EXTERNAL_ID',
|
||||||
'ROLE_SESSION_NAME',
|
'ROLE_SESSION_NAME',
|
||||||
'ROLE_SKIP_SESSION_TAGGING',
|
'ROLE_SKIP_SESSION_TAGGING',
|
||||||
|
'TRANSITIVE_TAG_KEYS',
|
||||||
'INLINE_SESSION_POLICY',
|
'INLINE_SESSION_POLICY',
|
||||||
'MANAGED_SESSION_POLICIES',
|
'MANAGED_SESSION_POLICIES',
|
||||||
'OUTPUT_CREDENTIALS',
|
'OUTPUT_CREDENTIALS',
|
||||||
@@ -28,6 +52,8 @@ export function translateEnvVariables() {
|
|||||||
'RETRY_MAX_ATTEMPTS',
|
'RETRY_MAX_ATTEMPTS',
|
||||||
'SPECIAL_CHARACTERS_WORKAROUND',
|
'SPECIAL_CHARACTERS_WORKAROUND',
|
||||||
'USE_EXISTING_CREDENTIALS',
|
'USE_EXISTING_CREDENTIALS',
|
||||||
|
'NO_PROXY',
|
||||||
|
'OVERWRITE_AWS_PROFILE',
|
||||||
];
|
];
|
||||||
// Treat HTTPS_PROXY as HTTP_PROXY. Precedence is HTTPS_PROXY > HTTP_PROXY
|
// Treat HTTPS_PROXY as HTTP_PROXY. Precedence is HTTPS_PROXY > HTTP_PROXY
|
||||||
if (process.env.HTTPS_PROXY) process.env.HTTP_PROXY = process.env.HTTPS_PROXY;
|
if (process.env.HTTPS_PROXY) process.env.HTTP_PROXY = process.env.HTTPS_PROXY;
|
||||||
@@ -109,15 +135,26 @@ export function exportRegion(region: string, outputEnvCredentials?: boolean) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtains account ID from STS Client and sets it as output
|
export async function getCallerIdentity(client: STSClient): Promise<{ Account: string; Arn: string; UserId?: string }> {
|
||||||
export async function exportAccountId(credentialsClient: CredentialsClient, maskAccountId?: boolean) {
|
|
||||||
const client = credentialsClient.stsClient;
|
|
||||||
const identity = await client.send(new GetCallerIdentityCommand({}));
|
const identity = await client.send(new GetCallerIdentityCommand({}));
|
||||||
const accountId = identity.Account;
|
if (!identity.Account || !identity.Arn) {
|
||||||
const arn = identity.Arn;
|
|
||||||
if (!accountId || !arn) {
|
|
||||||
throw new Error('Could not get Account ID or ARN from STS. Did you set credentials?');
|
throw new Error('Could not get Account ID or ARN from STS. Did you set credentials?');
|
||||||
}
|
}
|
||||||
|
const result: { Account: string; Arn: string; UserId?: string } = {
|
||||||
|
Account: identity.Account,
|
||||||
|
Arn: identity.Arn,
|
||||||
|
};
|
||||||
|
if (identity.UserId !== undefined) {
|
||||||
|
result.UserId = identity.UserId;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtains account ID from STS Client and sets it as output
|
||||||
|
export async function exportAccountId(credentialsClient: CredentialsClient, maskAccountId?: boolean) {
|
||||||
|
const identity = await getCallerIdentity(credentialsClient.stsClient);
|
||||||
|
const accountId = identity.Account;
|
||||||
|
const arn = identity.Arn;
|
||||||
if (maskAccountId) {
|
if (maskAccountId) {
|
||||||
core.setSecret(accountId);
|
core.setSecret(accountId);
|
||||||
core.setSecret(arn);
|
core.setSecret(arn);
|
||||||
@@ -175,20 +212,33 @@ export async function retryAndBackoff<T>(
|
|||||||
maxRetries = 12,
|
maxRetries = 12,
|
||||||
retries = 0,
|
retries = 0,
|
||||||
base = 50,
|
base = 50,
|
||||||
|
label?: string,
|
||||||
): Promise<T> {
|
): Promise<T> {
|
||||||
try {
|
try {
|
||||||
return await fn();
|
return await fn();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (!isRetryable) {
|
if (!isRetryable) {
|
||||||
|
core.debug(`retryAndBackoff: error is not retryable: ${errorMessage(err)}`);
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
// It's retryable, so sleep and retry.
|
// It's retryable, so sleep and retry.
|
||||||
await sleep(Math.random() * (2 ** retries * base));
|
const delay = Math.random() * (2 ** retries * base);
|
||||||
retries += 1;
|
const nextRetry = retries + 1;
|
||||||
if (retries >= maxRetries) {
|
const opName = label ? ` ${label}` : '';
|
||||||
|
|
||||||
|
core.info(
|
||||||
|
`Retry${opName}: attempt ${nextRetry} of ${maxRetries} failed: ${errorMessage(err)}. ` +
|
||||||
|
`Retrying after ${Math.floor(delay)}ms.`,
|
||||||
|
);
|
||||||
|
|
||||||
|
await sleep(delay);
|
||||||
|
|
||||||
|
if (nextRetry >= maxRetries) {
|
||||||
|
core.info(`Retry${opName}: reached max retries (${maxRetries}); giving up.`);
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
return await retryAndBackoff(fn, isRetryable, maxRetries, retries, base);
|
|
||||||
|
return await retryAndBackoff(fn, isRetryable, maxRetries, nextRetry, base, label);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,3 +264,135 @@ export async function areCredentialsValid(credentialsClient: CredentialsClient)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Like core.getBooleanInput, but respects the required option.
|
||||||
|
*
|
||||||
|
* From https://github.com/actions/toolkit/blob/6876e2a664ec02908178087905b9155e9892a437/packages/core/src/core.ts
|
||||||
|
*
|
||||||
|
* Gets the input value of the boolean type in the YAML 1.2 "core schema" specification.
|
||||||
|
* Support boolean input list: `true | True | TRUE | false | False | FALSE` .
|
||||||
|
* The return value is also in boolean type.
|
||||||
|
* ref: https://yaml.org/spec/1.2/spec.html#id2804923
|
||||||
|
*
|
||||||
|
* @param name name of the input to get
|
||||||
|
* @param options optional. See core.InputOptions. Also supports optional 'default' if the input is not set
|
||||||
|
* @returns boolean
|
||||||
|
*/
|
||||||
|
export function getBooleanInput(name: string, options?: core.InputOptions & { default?: boolean }): boolean {
|
||||||
|
const trueValue = ['true', 'True', 'TRUE'];
|
||||||
|
const falseValue = ['false', 'False', 'FALSE'];
|
||||||
|
const optionsWithoutDefault = { ...options };
|
||||||
|
delete optionsWithoutDefault.default;
|
||||||
|
const val = core.getInput(name, optionsWithoutDefault);
|
||||||
|
if (trueValue.includes(val)) return true;
|
||||||
|
if (falseValue.includes(val)) return false;
|
||||||
|
if (val === '') return options?.default ?? false;
|
||||||
|
throw new TypeError(
|
||||||
|
`Input does not meet YAML 1.2 "Core Schema" specification: ${name}\n` +
|
||||||
|
`Support boolean input list: \`true | True | TRUE | false | False | FALSE\``,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// O_NOFOLLOW is undefined on Windows. This sets it to 0 if it's not defined.
|
||||||
|
const O_NOFOLLOW: number = (fs.constants as { O_NOFOLLOW?: number }).O_NOFOLLOW ?? 0;
|
||||||
|
|
||||||
|
export function isAllowListed(filePath: string): boolean {
|
||||||
|
// Kubelet projects service-account tokens through a symlink chain
|
||||||
|
// (token -> ..data/token, ..data -> ..<timestamp>/). The containing path is
|
||||||
|
// kubelet-controlled, so we allow symlink-following reads of this fixed
|
||||||
|
// location only.
|
||||||
|
const KUBERNETES_TOKEN_PATH_REGEX = /^\/var\/run\/secrets\/[^/]+\/serviceaccount\/token$/;
|
||||||
|
|
||||||
|
if (process.platform !== 'win32') {
|
||||||
|
// No Kubernetes token paths on Windows
|
||||||
|
return KUBERNETES_TOKEN_PATH_REGEX.test(path.posix.normalize(filePath));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isSymlink(filePath: string): boolean {
|
||||||
|
try {
|
||||||
|
return fs.lstatSync(filePath).isSymbolicLink();
|
||||||
|
} catch (err) {
|
||||||
|
if ((err as NodeJS.ErrnoException).code === 'ENOENT') return false;
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Refuses if filePath or its parent directory is a symbolic link.
|
||||||
|
function refuseSymlinkOnPath(filePath: string): void {
|
||||||
|
const parent = path.dirname(filePath);
|
||||||
|
if (parent !== filePath && isSymlink(parent)) {
|
||||||
|
throw new Error(`Refusing ${filePath} (parent directory is a symbolic link)`);
|
||||||
|
}
|
||||||
|
if (isSymlink(filePath)) {
|
||||||
|
throw new Error(`Refusing ${filePath} (path is a symbolic link)`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function assertRegularFile(fd: number, filePath: string): void {
|
||||||
|
const stats = fs.fstatSync(fd);
|
||||||
|
if (!stats.isFile()) {
|
||||||
|
throw new Error(`${filePath} (path is not a regular file)`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ENOENT: file does not exist
|
||||||
|
// ELOOP: too many symbolic links (from NOFOLLOW)
|
||||||
|
|
||||||
|
export function readFileUtf8(filePath: string): string | null {
|
||||||
|
const allowSymlink = isAllowListed(filePath);
|
||||||
|
if (!allowSymlink) {
|
||||||
|
refuseSymlinkOnPath(filePath);
|
||||||
|
}
|
||||||
|
const openFlags = fs.constants.O_RDONLY | (allowSymlink ? 0 : O_NOFOLLOW);
|
||||||
|
let fd: number;
|
||||||
|
try {
|
||||||
|
fd = fs.openSync(filePath, openFlags);
|
||||||
|
} catch (err) {
|
||||||
|
const code = (err as NodeJS.ErrnoException).code;
|
||||||
|
if (code === 'ENOENT') return null;
|
||||||
|
if (code === 'ELOOP') {
|
||||||
|
throw new Error(`Refusing ${filePath} (path is a symbolic link)`);
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
assertRegularFile(fd, filePath);
|
||||||
|
return fs.readFileSync(fd, 'utf-8');
|
||||||
|
} finally {
|
||||||
|
fs.closeSync(fd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function writeFileUtf8(filePath: string, content: string, mode = 0o600): void {
|
||||||
|
refuseSymlinkOnPath(filePath);
|
||||||
|
let fd: number;
|
||||||
|
try {
|
||||||
|
fd = fs.openSync(filePath, fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_TRUNC | O_NOFOLLOW, mode);
|
||||||
|
} catch (err) {
|
||||||
|
if ((err as NodeJS.ErrnoException).code === 'ELOOP') {
|
||||||
|
throw new Error(`Refusing ${filePath} (path is a symbolic link)`);
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
assertRegularFile(fd, filePath);
|
||||||
|
// openSync only applies mode on creation.
|
||||||
|
// If the file already exists, we need to ensure the mode is correct.
|
||||||
|
if (process.platform !== 'win32') {
|
||||||
|
fs.fchmodSync(fd, mode);
|
||||||
|
}
|
||||||
|
fs.writeFileSync(fd, content);
|
||||||
|
} finally {
|
||||||
|
fs.closeSync(fd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function mkdir(dir: string, mode = 0o700): void {
|
||||||
|
fs.mkdirSync(dir, { recursive: true, mode });
|
||||||
|
if (isSymlink(dir)) {
|
||||||
|
throw new Error(`Refusing ${dir} (path is a symbolic link)`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+169
-68
@@ -8,82 +8,95 @@ import {
|
|||||||
exportAccountId,
|
exportAccountId,
|
||||||
exportCredentials,
|
exportCredentials,
|
||||||
exportRegion,
|
exportRegion,
|
||||||
|
getBooleanInput,
|
||||||
retryAndBackoff,
|
retryAndBackoff,
|
||||||
translateEnvVariables,
|
translateEnvVariables,
|
||||||
unsetCredentials,
|
unsetCredentials,
|
||||||
verifyKeys,
|
verifyKeys,
|
||||||
} from './helpers';
|
} from './helpers';
|
||||||
|
import { writeProfileFiles } from './profileManager';
|
||||||
|
|
||||||
const DEFAULT_ROLE_DURATION = 3600; // One hour (seconds)
|
const DEFAULT_ROLE_DURATION = 3600; // One hour (seconds)
|
||||||
const ROLE_SESSION_NAME = 'GitHubActions';
|
const ROLE_SESSION_NAME = 'GitHubActions';
|
||||||
const REGION_REGEX = /^[a-z0-9-]+$/g;
|
const REGION_REGEX = /^[a-z0-9-]+$/g;
|
||||||
|
const ROLE_SESSION_NAME_REGEX = /^[\w+=,.@-]*$/;
|
||||||
|
|
||||||
export async function run() {
|
export async function run() {
|
||||||
try {
|
try {
|
||||||
translateEnvVariables();
|
translateEnvVariables();
|
||||||
// Get inputs
|
// Get inputs
|
||||||
|
// Undefined inputs are empty strings ( or empty arrays)
|
||||||
const AccessKeyId = core.getInput('aws-access-key-id', { required: false });
|
const AccessKeyId = core.getInput('aws-access-key-id', { required: false });
|
||||||
const SecretAccessKey = core.getInput('aws-secret-access-key', {
|
const SecretAccessKey = core.getInput('aws-secret-access-key', { required: false });
|
||||||
required: false,
|
const sessionTokenInput = core.getInput('aws-session-token', { required: false });
|
||||||
});
|
|
||||||
const sessionTokenInput = core.getInput('aws-session-token', {
|
|
||||||
required: false,
|
|
||||||
});
|
|
||||||
const SessionToken = sessionTokenInput === '' ? undefined : sessionTokenInput;
|
const SessionToken = sessionTokenInput === '' ? undefined : sessionTokenInput;
|
||||||
const region = core.getInput('aws-region', { required: true });
|
const region = core.getInput('aws-region', { required: true });
|
||||||
|
const awsProfile = core.getInput('aws-profile', { required: false });
|
||||||
|
const overwriteAwsProfile = getBooleanInput('overwrite-aws-profile', { required: false });
|
||||||
const roleToAssume = core.getInput('role-to-assume', { required: false });
|
const roleToAssume = core.getInput('role-to-assume', { required: false });
|
||||||
const audience = core.getInput('audience', { required: false });
|
const audience = core.getInput('audience', { required: false });
|
||||||
const maskAccountIdInput = core.getInput('mask-aws-account-id', { required: false }) || 'false';
|
const maskAccountId = getBooleanInput('mask-aws-account-id', { required: false });
|
||||||
const maskAccountId = maskAccountIdInput.toLowerCase() === 'true';
|
const roleExternalId = core.getInput('role-external-id', { required: false });
|
||||||
const roleExternalId = core.getInput('role-external-id', {
|
const webIdentityTokenFile = core.getInput('web-identity-token-file', { required: false });
|
||||||
required: false,
|
|
||||||
});
|
|
||||||
const webIdentityTokenFile = core.getInput('web-identity-token-file', {
|
|
||||||
required: false,
|
|
||||||
});
|
|
||||||
const roleDuration =
|
const roleDuration =
|
||||||
Number.parseInt(core.getInput('role-duration-seconds', { required: false })) || DEFAULT_ROLE_DURATION;
|
Number.parseInt(core.getInput('role-duration-seconds', { required: false })) || DEFAULT_ROLE_DURATION;
|
||||||
const roleSessionName = core.getInput('role-session-name', { required: false }) || ROLE_SESSION_NAME;
|
const roleSessionName = core.getInput('role-session-name', { required: false }) || ROLE_SESSION_NAME;
|
||||||
const roleSkipSessionTaggingInput = core.getInput('role-skip-session-tagging', { required: false }) || 'false';
|
const roleSkipSessionTagging = getBooleanInput('role-skip-session-tagging', { required: false });
|
||||||
const roleSkipSessionTagging = roleSkipSessionTaggingInput.toLowerCase() === 'true';
|
const transitiveTagKeys = core.getMultilineInput('transitive-tag-keys', { required: false });
|
||||||
const proxyServer = core.getInput('http-proxy', { required: false }) || process.env.HTTP_PROXY;
|
const proxyServer = core.getInput('http-proxy', { required: false }) || process.env.HTTP_PROXY;
|
||||||
const inlineSessionPolicy = core.getInput('inline-session-policy', {
|
const customTags = core.getInput('custom-tags', { required: false });
|
||||||
required: false,
|
const inlineSessionPolicy = core.getInput('inline-session-policy', { required: false });
|
||||||
|
const managedSessionPolicies = core.getMultilineInput('managed-session-policies', { required: false }).map((p) => {
|
||||||
|
return { arn: p };
|
||||||
});
|
});
|
||||||
const managedSessionPoliciesInput = core.getMultilineInput('managed-session-policies', { required: false });
|
const roleChaining = getBooleanInput('role-chaining', { required: false });
|
||||||
const managedSessionPolicies: { arn: string }[] = [];
|
const outputCredentials = getBooleanInput('output-credentials', { required: false });
|
||||||
const roleChainingInput = core.getInput('role-chaining', { required: false }) || 'false';
|
// Default to always outputting environment credentials unless profile is specified. If profile is specified, default to
|
||||||
const roleChaining = roleChainingInput.toLowerCase() === 'true';
|
// no environment credentials (but still output them if the user specifically requests it).
|
||||||
const outputCredentialsInput = core.getInput('output-credentials', { required: false }) || 'false';
|
const outputEnvCredentials = getBooleanInput('output-env-credentials', { required: false, default: !awsProfile });
|
||||||
const outputCredentials = outputCredentialsInput.toLowerCase() === 'true';
|
const unsetCurrentCredentials = getBooleanInput('unset-current-credentials', { required: false });
|
||||||
const outputEnvCredentialsInput = core.getInput('output-env-credentials', { required: false }) || 'true';
|
let disableRetry = getBooleanInput('disable-retry', { required: false });
|
||||||
const outputEnvCredentials = outputEnvCredentialsInput.toLowerCase() === 'true';
|
const specialCharacterWorkaround = getBooleanInput('special-characters-workaround', { required: false });
|
||||||
const unsetCurrentCredentialsInput = core.getInput('unset-current-credentials', { required: false }) || 'false';
|
const useExistingCredentials = core.getInput('use-existing-credentials', { required: false });
|
||||||
const unsetCurrentCredentials = unsetCurrentCredentialsInput.toLowerCase() === 'true';
|
|
||||||
const disableRetryInput = core.getInput('disable-retry', { required: false }) || 'false';
|
|
||||||
let disableRetry = disableRetryInput.toLowerCase() === 'true';
|
|
||||||
const specialCharacterWorkaroundInput =
|
|
||||||
core.getInput('special-characters-workaround', { required: false }) || 'false';
|
|
||||||
const specialCharacterWorkaround = specialCharacterWorkaroundInput.toLowerCase() === 'true';
|
|
||||||
const useExistingCredentialsInput = core.getInput('use-existing-credentials', { required: false }) || 'false';
|
|
||||||
const useExistingCredentials = useExistingCredentialsInput.toLowerCase() === 'true';
|
|
||||||
let maxRetries = Number.parseInt(core.getInput('retry-max-attempts', { required: false })) || 12;
|
let maxRetries = Number.parseInt(core.getInput('retry-max-attempts', { required: false })) || 12;
|
||||||
switch (true) {
|
const expectedAccountIds = core
|
||||||
case specialCharacterWorkaround:
|
.getInput('allowed-account-ids', { required: false })
|
||||||
|
.split(',')
|
||||||
|
.map((s) => s.trim());
|
||||||
|
const forceSkipOidc = getBooleanInput('force-skip-oidc', { required: false });
|
||||||
|
const noProxy = core.getInput('no-proxy', { required: false });
|
||||||
|
const stsEndpoint = core.getInput('sts-endpoint', { required: false });
|
||||||
|
const globalTimeout = Number.parseInt(core.getInput('action-timeout-s', { required: false })) || 0;
|
||||||
|
|
||||||
|
let timeoutId: NodeJS.Timeout | undefined;
|
||||||
|
if (globalTimeout > 0) {
|
||||||
|
core.info(`Setting a global timeout of ${globalTimeout} seconds for the action`);
|
||||||
|
timeoutId = setTimeout(() => {
|
||||||
|
core.setFailed(`Action timed out after ${globalTimeout} seconds`);
|
||||||
|
process.exit(1);
|
||||||
|
}, globalTimeout * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (forceSkipOidc && roleToAssume && !AccessKeyId && !webIdentityTokenFile) {
|
||||||
|
throw new Error(
|
||||||
|
"If 'force-skip-oidc' is true and 'role-to-assume' is set, 'aws-access-key-id' or 'web-identity-token-file' must be set",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (specialCharacterWorkaround) {
|
||||||
// 😳
|
// 😳
|
||||||
disableRetry = false;
|
disableRetry = false;
|
||||||
maxRetries = 12;
|
maxRetries = 12;
|
||||||
break;
|
} else if (maxRetries < 1) {
|
||||||
case maxRetries < 1:
|
|
||||||
maxRetries = 1;
|
maxRetries = 1;
|
||||||
break;
|
|
||||||
}
|
|
||||||
for (const managedSessionPolicy of managedSessionPoliciesInput) {
|
|
||||||
managedSessionPolicies.push({ arn: managedSessionPolicy });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const withRetry = <T>(fn: () => Promise<T>, label: string): Promise<T> =>
|
||||||
|
retryAndBackoff(fn, !disableRetry, maxRetries, 0, 50, label);
|
||||||
|
|
||||||
// Logic to decide whether to attempt to use OIDC or not
|
// Logic to decide whether to attempt to use OIDC or not
|
||||||
const useGitHubOIDCProvider = () => {
|
const useGitHubOIDCProvider = () => {
|
||||||
|
if (forceSkipOidc) return false;
|
||||||
// The `ACTIONS_ID_TOKEN_REQUEST_TOKEN` environment variable is set when the `id-token` permission is granted.
|
// The `ACTIONS_ID_TOKEN_REQUEST_TOKEN` environment variable is set when the `id-token` permission is granted.
|
||||||
// This is necessary to authenticate with OIDC, but not strictly set just for OIDC. If it is not set and all other
|
// This is necessary to authenticate with OIDC, but not strictly set just for OIDC. If it is not set and all other
|
||||||
// checks pass, it is likely but not guaranteed that the user needs but lacks this permission in their workflow.
|
// checks pass, it is likely but not guaranteed that the user needs but lacks this permission in their workflow.
|
||||||
@@ -116,10 +129,35 @@ export async function run() {
|
|||||||
if (!region.match(REGION_REGEX)) {
|
if (!region.match(REGION_REGEX)) {
|
||||||
throw new Error(`Region is not valid: ${region}`);
|
throw new Error(`Region is not valid: ${region}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (roleSessionName.length < 2 || roleSessionName.length > 64) {
|
||||||
|
throw new Error(
|
||||||
|
`Role session name must be between 2 and 64 characters, got ${roleSessionName.length}: '${roleSessionName}'`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (!roleSessionName.match(ROLE_SESSION_NAME_REGEX)) {
|
||||||
|
throw new Error(
|
||||||
|
`Role session name is not valid: '${roleSessionName}'. Must satisfy regular expression pattern: [\\w+=,.@-]*`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
exportRegion(region, outputEnvCredentials);
|
exportRegion(region, outputEnvCredentials);
|
||||||
|
|
||||||
// Instantiate credentials client
|
// Instantiate credentials client
|
||||||
const credentialsClient = new CredentialsClient({ region, proxyServer });
|
const clientProps: {
|
||||||
|
region: string;
|
||||||
|
proxyServer?: string;
|
||||||
|
noProxy?: string;
|
||||||
|
stsEndpoint?: string;
|
||||||
|
roleChaining: boolean;
|
||||||
|
} = {
|
||||||
|
region,
|
||||||
|
roleChaining,
|
||||||
|
};
|
||||||
|
if (proxyServer) clientProps.proxyServer = proxyServer;
|
||||||
|
if (noProxy) clientProps.noProxy = noProxy;
|
||||||
|
if (stsEndpoint) clientProps.stsEndpoint = stsEndpoint;
|
||||||
|
const credentialsClient = new CredentialsClient(clientProps);
|
||||||
let sourceAccountId: string;
|
let sourceAccountId: string;
|
||||||
let webIdentityToken: string;
|
let webIdentityToken: string;
|
||||||
|
|
||||||
@@ -128,6 +166,7 @@ export async function run() {
|
|||||||
const validCredentials = await areCredentialsValid(credentialsClient);
|
const validCredentials = await areCredentialsValid(credentialsClient);
|
||||||
if (validCredentials) {
|
if (validCredentials) {
|
||||||
core.notice('Pre-existing credentials are valid. No need to generate new ones.');
|
core.notice('Pre-existing credentials are valid. No need to generate new ones.');
|
||||||
|
if (timeoutId) clearTimeout(timeoutId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
core.notice('No valid credentials exist. Running as normal.');
|
core.notice('No valid credentials exist. Running as normal.');
|
||||||
@@ -137,13 +176,9 @@ export async function run() {
|
|||||||
// Else, export credentials provided as input
|
// Else, export credentials provided as input
|
||||||
if (useGitHubOIDCProvider()) {
|
if (useGitHubOIDCProvider()) {
|
||||||
try {
|
try {
|
||||||
webIdentityToken = await retryAndBackoff(
|
webIdentityToken = await withRetry(async () => {
|
||||||
async () => {
|
|
||||||
return core.getIDToken(audience);
|
return core.getIDToken(audience);
|
||||||
},
|
}, 'getIDToken');
|
||||||
!disableRetry,
|
|
||||||
maxRetries,
|
|
||||||
);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(`getIDToken call failed: ${errorMessage(error)}`);
|
throw new Error(`getIDToken call failed: ${errorMessage(error)}`);
|
||||||
}
|
}
|
||||||
@@ -156,26 +191,48 @@ export async function run() {
|
|||||||
// the source credentials to already be masked as secrets
|
// the source credentials to already be masked as secrets
|
||||||
// in any error messages.
|
// in any error messages.
|
||||||
exportCredentials({ AccessKeyId, SecretAccessKey, SessionToken }, outputCredentials, outputEnvCredentials);
|
exportCredentials({ AccessKeyId, SecretAccessKey, SessionToken }, outputCredentials, outputEnvCredentials);
|
||||||
|
|
||||||
|
// If using IAM User Credentials, write to profile now so that the assumeRole call can succeed (and also for
|
||||||
|
// credential validation before role assumption).
|
||||||
|
if (awsProfile) {
|
||||||
|
writeProfileFiles(awsProfile, { AccessKeyId, SecretAccessKey, SessionToken }, region, overwriteAwsProfile);
|
||||||
|
}
|
||||||
} else if (!webIdentityTokenFile && !roleChaining) {
|
} else if (!webIdentityTokenFile && !roleChaining) {
|
||||||
// Proceed only if credentials can be picked up
|
// Proceed only if credentials can be picked up
|
||||||
await credentialsClient.validateCredentials();
|
await withRetry(
|
||||||
sourceAccountId = await exportAccountId(credentialsClient, maskAccountId);
|
() => credentialsClient.validateCredentials(undefined, roleChaining, expectedAccountIds),
|
||||||
|
'validateCredentials',
|
||||||
|
);
|
||||||
|
sourceAccountId = await withRetry(() => exportAccountId(credentialsClient, maskAccountId), 'exportAccountId');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (AccessKeyId || roleChaining) {
|
if (AccessKeyId || roleChaining) {
|
||||||
// Validate that the SDK can actually pick up credentials.
|
// Validate that the SDK can actually pick up credentials.
|
||||||
// This validates cases where this action is using existing environment credentials,
|
// This validates cases where this action is using existing environment credentials,
|
||||||
// and cases where the user intended to provide input credentials but the secrets inputs resolved to empty strings.
|
// and cases where the user intended to provide input credentials but the secrets inputs resolved to empty strings.
|
||||||
await credentialsClient.validateCredentials(AccessKeyId, roleChaining);
|
// Skip when output-env-credentials is false: input IAM keys were not written to env, so
|
||||||
sourceAccountId = await exportAccountId(credentialsClient, maskAccountId);
|
// the default chain would resolve to ambient runner credentials and the access-key check
|
||||||
|
// would spuriously fail (see #1554).
|
||||||
|
if (outputEnvCredentials) {
|
||||||
|
await withRetry(
|
||||||
|
() => credentialsClient.validateCredentials(AccessKeyId, roleChaining, expectedAccountIds),
|
||||||
|
'validateCredentials',
|
||||||
|
);
|
||||||
|
sourceAccountId = await withRetry(() => exportAccountId(credentialsClient, maskAccountId), 'exportAccountId');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (customTags && (useGitHubOIDCProvider() || webIdentityTokenFile)) {
|
||||||
|
core.warning(
|
||||||
|
"'custom-tags' is set but will be ignored because session tags cannot be applied when using OIDC or web identity token authentication. " +
|
||||||
|
'Tags are controlled by the identity provider token claims in these authentication flows.',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get role credentials if configured to do so
|
// Get role credentials if configured to do so
|
||||||
if (roleToAssume) {
|
if (roleToAssume) {
|
||||||
let roleCredentials: AssumeRoleCommandOutput;
|
let roleCredentials: AssumeRoleCommandOutput;
|
||||||
do {
|
do {
|
||||||
roleCredentials = await retryAndBackoff(
|
roleCredentials = await withRetry(async () => {
|
||||||
async () => {
|
|
||||||
return assumeRole({
|
return assumeRole({
|
||||||
credentialsClient,
|
credentialsClient,
|
||||||
sourceAccountId,
|
sourceAccountId,
|
||||||
@@ -184,36 +241,80 @@ export async function run() {
|
|||||||
roleDuration,
|
roleDuration,
|
||||||
roleSessionName,
|
roleSessionName,
|
||||||
roleSkipSessionTagging,
|
roleSkipSessionTagging,
|
||||||
|
transitiveTagKeys,
|
||||||
webIdentityTokenFile,
|
webIdentityTokenFile,
|
||||||
webIdentityToken,
|
webIdentityToken,
|
||||||
inlineSessionPolicy,
|
inlineSessionPolicy,
|
||||||
managedSessionPolicies,
|
managedSessionPolicies,
|
||||||
|
customTags,
|
||||||
});
|
});
|
||||||
},
|
}, 'AssumeRole');
|
||||||
!disableRetry,
|
|
||||||
maxRetries,
|
|
||||||
);
|
|
||||||
} while (specialCharacterWorkaround && !verifyKeys(roleCredentials.Credentials));
|
} while (specialCharacterWorkaround && !verifyKeys(roleCredentials.Credentials));
|
||||||
core.info(`Authenticated as assumedRoleId ${roleCredentials.AssumedRoleUser?.AssumedRoleId}`);
|
core.info(`Authenticated as assumedRoleId ${roleCredentials.AssumedRoleUser?.AssumedRoleId}`);
|
||||||
exportCredentials(roleCredentials.Credentials, outputCredentials, outputEnvCredentials);
|
exportCredentials(roleCredentials.Credentials, outputCredentials, outputEnvCredentials);
|
||||||
// We need to validate the credentials in 2 of our use-cases
|
// Validate that the SDK can pick up the assumed-role credentials from the environment.
|
||||||
// First: self-hosted runners. If the GITHUB_ACTIONS environment variable
|
// Skip when output-env-credentials is false: the credentials were never written to env,
|
||||||
// is set to `true` then we are NOT in a self-hosted runner.
|
// so the default credential provider chain would resolve to ambient runner credentials
|
||||||
// Second: Customer provided credentials manually (IAM User keys stored in GH Secrets)
|
// (e.g. an EC2 instance profile) and the access-key-id check would spuriously fail.
|
||||||
if (!process.env.GITHUB_ACTIONS || AccessKeyId) {
|
// Skip when using a profile: validation runs after the profile file is written below.
|
||||||
await credentialsClient.validateCredentials(roleCredentials.Credentials?.AccessKeyId);
|
if ((!process.env.GITHUB_ACTIONS || AccessKeyId) && !awsProfile && outputEnvCredentials) {
|
||||||
|
await withRetry(
|
||||||
|
() =>
|
||||||
|
credentialsClient.validateCredentials(
|
||||||
|
roleCredentials.Credentials?.AccessKeyId,
|
||||||
|
roleChaining,
|
||||||
|
expectedAccountIds,
|
||||||
|
),
|
||||||
|
'validateCredentials',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (outputEnvCredentials) {
|
if (outputEnvCredentials) {
|
||||||
await exportAccountId(credentialsClient, maskAccountId);
|
await withRetry(() => exportAccountId(credentialsClient, maskAccountId), 'exportAccountId');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write profile files if profile mode is enabled
|
||||||
|
if (awsProfile) {
|
||||||
|
if (!roleCredentials.Credentials) {
|
||||||
|
throw new Error('AssumeRole call succeeded but returned no credentials');
|
||||||
|
}
|
||||||
|
// If user provided IAM User Credentials and then we assumed a role, overwrite the profile file to add
|
||||||
|
// the session token. (this only overwrites the profile within a single run of the action).
|
||||||
|
// We then validate the credentials to make sure they work.
|
||||||
|
if (AccessKeyId || !process.env.GITHUB_ACTIONS) {
|
||||||
|
writeProfileFiles(awsProfile, roleCredentials.Credentials, region, true);
|
||||||
|
await withRetry(
|
||||||
|
() =>
|
||||||
|
credentialsClient.validateCredentials(
|
||||||
|
roleCredentials.Credentials?.AccessKeyId,
|
||||||
|
roleChaining,
|
||||||
|
expectedAccountIds,
|
||||||
|
),
|
||||||
|
'validateCredentials',
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
writeProfileFiles(awsProfile, roleCredentials.Credentials, region, overwriteAwsProfile);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (outputEnvCredentials) {
|
||||||
|
core.exportVariable('AWS_PROFILE', awsProfile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
core.info('Proceeding with IAM user credentials');
|
core.info('Proceeding with IAM user credentials');
|
||||||
|
|
||||||
|
if (awsProfile) {
|
||||||
|
if (outputEnvCredentials) {
|
||||||
|
core.exportVariable('AWS_PROFILE', awsProfile);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear timeout on successful completion
|
||||||
|
if (timeoutId) clearTimeout(timeoutId);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(errorMessage(error));
|
core.setFailed(errorMessage(error));
|
||||||
|
|
||||||
const showStackTrace = process.env.SHOW_STACK_TRACE;
|
const showStackTrace = process.env.SHOW_STACK_TRACE;
|
||||||
|
|
||||||
if (showStackTrace === 'true') {
|
if (showStackTrace === 'true') {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,206 @@
|
|||||||
|
import * as os from 'node:os';
|
||||||
|
import * as path from 'node:path';
|
||||||
|
import * as core from '@actions/core';
|
||||||
|
import type { Credentials } from '@aws-sdk/client-sts';
|
||||||
|
import { mkdir, readFileUtf8, writeFileUtf8 } from './helpers';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse an INI-format string into a nested object.
|
||||||
|
* Preserves literal section names (e.g. "profile dev" stays as-is).
|
||||||
|
*/
|
||||||
|
export function parseIni(iniData: string): Record<string, Record<string, string>> {
|
||||||
|
const result: Record<string, Record<string, string>> = {};
|
||||||
|
let currentSection: string | undefined;
|
||||||
|
|
||||||
|
for (const line of iniData.split(/\r?\n/)) {
|
||||||
|
const trimmed = line.trim();
|
||||||
|
if (!trimmed || trimmed.startsWith(';') || trimmed.startsWith('#')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const sectionMatch = trimmed.match(/^\[([^\]]*)\]$/);
|
||||||
|
if (sectionMatch) {
|
||||||
|
currentSection = sectionMatch[1] as string;
|
||||||
|
if (currentSection === '__proto__') {
|
||||||
|
currentSection = undefined;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
result[currentSection] = result[currentSection] || {};
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentSection) {
|
||||||
|
const eqIndex = trimmed.indexOf('=');
|
||||||
|
if (eqIndex > 0) {
|
||||||
|
const key = trimmed.substring(0, eqIndex).trim();
|
||||||
|
const value = trimmed.substring(eqIndex + 1).trim();
|
||||||
|
if (key !== '__proto__') {
|
||||||
|
const section = result[currentSection];
|
||||||
|
if (section) {
|
||||||
|
section[key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialize a nested object into INI-format string.
|
||||||
|
*/
|
||||||
|
export function stringifyIni(data: Record<string, Record<string, string>>): string {
|
||||||
|
const sections: string[] = [];
|
||||||
|
for (const [sectionName, sectionData] of Object.entries(data)) {
|
||||||
|
const lines: string[] = [`[${sectionName}]`];
|
||||||
|
for (const [key, value] of Object.entries(sectionData)) {
|
||||||
|
lines.push(`${key} = ${value}`);
|
||||||
|
}
|
||||||
|
sections.push(lines.join('\n'));
|
||||||
|
}
|
||||||
|
return `${sections.join('\n\n')}\n`;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ProfileFilePaths {
|
||||||
|
credentials: string;
|
||||||
|
config: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the file paths for AWS credentials and config files
|
||||||
|
* Respects AWS_SHARED_CREDENTIALS_FILE and AWS_CONFIG_FILE environment variables
|
||||||
|
*/
|
||||||
|
export function getProfileFilePaths(): ProfileFilePaths {
|
||||||
|
const credentialsPath = process.env.AWS_SHARED_CREDENTIALS_FILE || path.join(os.homedir(), '.aws', 'credentials');
|
||||||
|
const configPath = process.env.AWS_CONFIG_FILE || path.join(os.homedir(), '.aws', 'config');
|
||||||
|
|
||||||
|
return {
|
||||||
|
credentials: credentialsPath,
|
||||||
|
config: configPath,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure the AWS directory exists with secure permissions
|
||||||
|
* Creates the directory with 700 permissions (rwx for owner only)
|
||||||
|
*/
|
||||||
|
export function ensureAwsDirectoryExists(filePath: string): void {
|
||||||
|
const dir = path.dirname(filePath);
|
||||||
|
core.debug(`Ensuring directory exists: ${dir}`);
|
||||||
|
mkdir(dir, 0o700);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate profile name format
|
||||||
|
* Profile names must be non-empty, contain no whitespace, brackets, or path separators
|
||||||
|
*/
|
||||||
|
export function validateProfileName(profileName: string): void {
|
||||||
|
if (!profileName || profileName.trim() === '') {
|
||||||
|
throw new Error('aws-profile must not be empty');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (/\s/.test(profileName)) {
|
||||||
|
throw new Error('aws-profile must not contain whitespace');
|
||||||
|
}
|
||||||
|
|
||||||
|
// INI section names can't contain brackets
|
||||||
|
if (/[[\]]/.test(profileName)) {
|
||||||
|
throw new Error('aws-profile must not contain brackets');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prevent path traversal
|
||||||
|
if (profileName.includes('/') || profileName.includes('\\')) {
|
||||||
|
throw new Error('aws-profile must not contain path separators');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merge a profile section into an INI file
|
||||||
|
* Reads existing file, updates the specified section, and writes back
|
||||||
|
*/
|
||||||
|
export function mergeProfileSection(
|
||||||
|
filePath: string,
|
||||||
|
sectionName: string,
|
||||||
|
data: Record<string, string>,
|
||||||
|
overwriteAwsProfile: boolean,
|
||||||
|
): void {
|
||||||
|
const fileContent = readFileUtf8(filePath);
|
||||||
|
const existingContent: Record<string, Record<string, string>> = fileContent === null ? {} : parseIni(fileContent);
|
||||||
|
|
||||||
|
if (existingContent[sectionName] && !overwriteAwsProfile) {
|
||||||
|
throw new Error(
|
||||||
|
`Profile with name "${sectionName}" already exists. Please use the overwrite-aws-profile input if you want to overwrite existing profiles.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// Merge: update existing profile or add new one
|
||||||
|
existingContent[sectionName] = data;
|
||||||
|
|
||||||
|
const content = stringifyIni(existingContent);
|
||||||
|
|
||||||
|
core.debug(`Writing profile to ${filePath}`);
|
||||||
|
writeFileUtf8(filePath, content, 0o600);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write AWS profile files with credentials and configuration
|
||||||
|
* This is the main entry point for profile file operations
|
||||||
|
*
|
||||||
|
* @param profileName - Name of the AWS profile to configure
|
||||||
|
* @param credentials - AWS credentials (access key, secret key, session token)
|
||||||
|
* @param region - AWS region
|
||||||
|
*/
|
||||||
|
export function writeProfileFiles(
|
||||||
|
profileName: string,
|
||||||
|
credentials: Partial<Credentials>,
|
||||||
|
region: string,
|
||||||
|
overwriteAwsProfile: boolean,
|
||||||
|
): void {
|
||||||
|
try {
|
||||||
|
// Validate profile name
|
||||||
|
validateProfileName(profileName);
|
||||||
|
|
||||||
|
const paths = getProfileFilePaths();
|
||||||
|
|
||||||
|
// Ensure .aws directory exists
|
||||||
|
ensureAwsDirectoryExists(paths.credentials);
|
||||||
|
ensureAwsDirectoryExists(paths.config);
|
||||||
|
|
||||||
|
// Prepare credentials data
|
||||||
|
const credentialsData: Record<string, string> = {};
|
||||||
|
if (credentials.AccessKeyId) {
|
||||||
|
credentialsData.aws_access_key_id = credentials.AccessKeyId;
|
||||||
|
}
|
||||||
|
if (credentials.SecretAccessKey) {
|
||||||
|
credentialsData.aws_secret_access_key = credentials.SecretAccessKey;
|
||||||
|
}
|
||||||
|
if (credentials.SessionToken) {
|
||||||
|
credentialsData.aws_session_token = credentials.SessionToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Credentials file uses [profileName] syntax
|
||||||
|
const credsSectionName = profileName;
|
||||||
|
|
||||||
|
// Config file uses [profile profileName] syntax, except for 'default'
|
||||||
|
const configSectionName = profileName === 'default' ? 'default' : `profile ${profileName}`;
|
||||||
|
|
||||||
|
// Prepare config data
|
||||||
|
const configData: Record<string, string> = {
|
||||||
|
region: region,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Write to credentials file
|
||||||
|
core.info(`Writing credentials to profile: ${profileName}`);
|
||||||
|
mergeProfileSection(paths.credentials, credsSectionName, credentialsData, overwriteAwsProfile);
|
||||||
|
|
||||||
|
// Write to config file
|
||||||
|
core.info(`Writing config to profile: ${profileName}`);
|
||||||
|
mergeProfileSection(paths.config, configSectionName, configData, overwriteAwsProfile);
|
||||||
|
|
||||||
|
core.info(`✓ Successfully configured AWS profile: ${profileName}`);
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error(
|
||||||
|
`Failed to write AWS profile '${profileName}': ${error instanceof Error ? error.message : String(error)}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
import type * as http from 'node:http';
|
||||||
|
import { describe, expect, test } from 'vitest';
|
||||||
|
import { type ProxyOptions, ProxyResolver } from '../src/ProxyResolver';
|
||||||
|
|
||||||
|
describe('ProxyResolver', () => {
|
||||||
|
const mockReq = {} as http.ClientRequest;
|
||||||
|
|
||||||
|
test('returns http proxy for http URLs', () => {
|
||||||
|
const options: ProxyOptions = { httpProxy: 'http://proxy:8080' };
|
||||||
|
const resolver = new ProxyResolver(options);
|
||||||
|
|
||||||
|
expect(resolver.getProxyForUrl('http://example.com', mockReq)).toBe('http://proxy:8080');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('returns https proxy for https URLs', () => {
|
||||||
|
const options: ProxyOptions = { httpsProxy: 'https://proxy:8080' };
|
||||||
|
const resolver = new ProxyResolver(options);
|
||||||
|
|
||||||
|
expect(resolver.getProxyForUrl('https://example.com', mockReq)).toBe('https://proxy:8080');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('returns empty string when no proxy configured', () => {
|
||||||
|
const resolver = new ProxyResolver({});
|
||||||
|
|
||||||
|
expect(resolver.getProxyForUrl('http://example.com', mockReq)).toBe('');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('respects noProxy setting', () => {
|
||||||
|
const options: ProxyOptions = {
|
||||||
|
httpProxy: 'http://proxy:8080',
|
||||||
|
noProxy: 'example.com',
|
||||||
|
};
|
||||||
|
const resolver = new ProxyResolver(options);
|
||||||
|
|
||||||
|
expect(resolver.getProxyForUrl('http://example.com', mockReq)).toBe('');
|
||||||
|
expect(resolver.getProxyForUrl('http://other.com', mockReq)).toBe('http://proxy:8080');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('handles invalid URLs', () => {
|
||||||
|
const resolver = new ProxyResolver({ httpProxy: 'http://proxy:8080' });
|
||||||
|
|
||||||
|
expect(resolver.getProxyForUrl('invalid-url', mockReq)).toBe('');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('handles wildcard noProxy', () => {
|
||||||
|
const options: ProxyOptions = {
|
||||||
|
httpProxy: 'http://proxy:8080',
|
||||||
|
noProxy: '*',
|
||||||
|
};
|
||||||
|
const resolver = new ProxyResolver(options);
|
||||||
|
|
||||||
|
expect(resolver.getProxyForUrl('http://example.com', mockReq)).toBe('');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('handles comma-separated noProxy list', () => {
|
||||||
|
const options: ProxyOptions = {
|
||||||
|
httpProxy: 'http://proxy:8080',
|
||||||
|
noProxy: 'example.com,test.com',
|
||||||
|
};
|
||||||
|
const resolver = new ProxyResolver(options);
|
||||||
|
|
||||||
|
expect(resolver.getProxyForUrl('http://example.com', mockReq)).toBe('');
|
||||||
|
expect(resolver.getProxyForUrl('http://test.com', mockReq)).toBe('');
|
||||||
|
expect(resolver.getProxyForUrl('http://other.com', mockReq)).toBe('http://proxy:8080');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('handles port-specific noProxy', () => {
|
||||||
|
const options: ProxyOptions = {
|
||||||
|
httpProxy: 'http://proxy:8080',
|
||||||
|
noProxy: 'example.com:80',
|
||||||
|
};
|
||||||
|
const resolver = new ProxyResolver(options);
|
||||||
|
|
||||||
|
expect(resolver.getProxyForUrl('http://example.com', mockReq)).toBe('');
|
||||||
|
expect(resolver.getProxyForUrl('http://example.com:8080', mockReq)).toBe('http://proxy:8080');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('handles wildcard domain noProxy', () => {
|
||||||
|
const options: ProxyOptions = {
|
||||||
|
httpProxy: 'http://proxy:8080',
|
||||||
|
noProxy: '*.example.com',
|
||||||
|
};
|
||||||
|
const resolver = new ProxyResolver(options);
|
||||||
|
|
||||||
|
expect(resolver.getProxyForUrl('http://sub.example.com', mockReq)).toBe('');
|
||||||
|
expect(resolver.getProxyForUrl('http://example.com', mockReq)).toBe('http://proxy:8080');
|
||||||
|
expect(resolver.getProxyForUrl('http://other.com', mockReq)).toBe('http://proxy:8080');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('handles empty noProxy entries', () => {
|
||||||
|
const options: ProxyOptions = {
|
||||||
|
httpProxy: 'http://proxy:8080',
|
||||||
|
noProxy: 'example.com, ,test.com',
|
||||||
|
};
|
||||||
|
const resolver = new ProxyResolver(options);
|
||||||
|
|
||||||
|
expect(resolver.getProxyForUrl('http://example.com', mockReq)).toBe('');
|
||||||
|
expect(resolver.getProxyForUrl('http://test.com', mockReq)).toBe('');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
import * as core from '@actions/core';
|
||||||
|
import { AssumeRoleWithWebIdentityCommand, GetCallerIdentityCommand, STSClient } from '@aws-sdk/client-sts';
|
||||||
|
import { mockClient } from 'aws-sdk-client-mock';
|
||||||
|
import { fs, vol } from 'memfs';
|
||||||
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||||
|
import * as helpers from '../src/helpers';
|
||||||
|
import { run } from '../src/index';
|
||||||
|
import mocks from './mockinputs.test';
|
||||||
|
|
||||||
|
vi.mock('node:fs');
|
||||||
|
vi.mock('@actions/core');
|
||||||
|
|
||||||
|
const mockedSTSClient = mockClient(STSClient);
|
||||||
|
|
||||||
|
describe('assumeRoleWithWebIdentityTokenFile', {}, () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
vi.restoreAllMocks();
|
||||||
|
vi.clearAllMocks();
|
||||||
|
mockedSTSClient.reset();
|
||||||
|
vol.reset();
|
||||||
|
helpers.withsleep(() => Promise.resolve());
|
||||||
|
vi.mocked(core.getInput).mockImplementation(mocks.getInput(mocks.WEBIDENTITY_TOKEN_FILE_INPUTS));
|
||||||
|
vi.mocked(core.getMultilineInput).mockReturnValue([]);
|
||||||
|
mockedSTSClient.on(GetCallerIdentityCommand).resolves({ ...mocks.outputs.GET_CALLER_IDENTITY });
|
||||||
|
process.env = { ...mocks.envs };
|
||||||
|
fs.mkdirSync('/home/github', { recursive: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
helpers.reset();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('refuses when the token file is a symlink and never calls STS', async () => {
|
||||||
|
fs.mkdirSync('/etc', { recursive: true });
|
||||||
|
fs.writeFileSync('/etc/passwd', 'root:x:0:0::/root:/bin/sh');
|
||||||
|
fs.symlinkSync('/etc/passwd', '/home/github/file.txt');
|
||||||
|
|
||||||
|
await run();
|
||||||
|
|
||||||
|
expect(core.setFailed).toHaveBeenCalledWith(expect.stringMatching(/Refusing .* \(.* symbolic link\)/));
|
||||||
|
expect(mockedSTSClient.commandCalls(AssumeRoleWithWebIdentityCommand)).toHaveLength(0);
|
||||||
|
expect(fs.readFileSync('/etc/passwd', 'utf-8')).toBe('root:x:0:0::/root:/bin/sh');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('preserves the existing missing-file error when the token file does not exist', async () => {
|
||||||
|
await run();
|
||||||
|
|
||||||
|
expect(core.setFailed).toHaveBeenCalledWith(expect.stringContaining('Web identity token file does not exist'));
|
||||||
|
expect(mockedSTSClient.commandCalls(AssumeRoleWithWebIdentityCommand)).toHaveLength(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('passes token contents to STS when the file is regular', async () => {
|
||||||
|
fs.writeFileSync('/home/github/file.txt', 'real-token');
|
||||||
|
mockedSTSClient.on(AssumeRoleWithWebIdentityCommand).resolves(mocks.outputs.STS_CREDENTIALS);
|
||||||
|
|
||||||
|
await run();
|
||||||
|
|
||||||
|
expect(core.setFailed).not.toHaveBeenCalled();
|
||||||
|
const calls = mockedSTSClient.commandCalls(AssumeRoleWithWebIdentityCommand);
|
||||||
|
expect(calls).toHaveLength(1);
|
||||||
|
expect(calls[0]?.args[0].input.WebIdentityToken).toBe('real-token');
|
||||||
|
});
|
||||||
|
});
|
||||||
+26
-11
@@ -5,20 +5,15 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|||||||
import { cleanup } from '../src/cleanup';
|
import { cleanup } from '../src/cleanup';
|
||||||
import mocks from './mockinputs.test';
|
import mocks from './mockinputs.test';
|
||||||
|
|
||||||
|
vi.mock('@actions/core');
|
||||||
|
|
||||||
const mockedSTSClient = mockClient(STSClient);
|
const mockedSTSClient = mockClient(STSClient);
|
||||||
|
|
||||||
describe('Configure AWS Credentials cleanup', {}, () => {
|
describe('Configure AWS Credentials cleanup', {}, () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// Reset mock state
|
vi.resetAllMocks();
|
||||||
vi.restoreAllMocks();
|
|
||||||
mockedSTSClient.reset();
|
mockedSTSClient.reset();
|
||||||
// Mock GitHub Actions core functions
|
vi.mocked(core.getInput).mockReturnValue('');
|
||||||
vi.spyOn(core, 'exportVariable').mockImplementation((_n, _v) => {});
|
|
||||||
vi.spyOn(core, 'setSecret').mockImplementation((_s) => {});
|
|
||||||
vi.spyOn(core, 'setFailed').mockImplementation((_m) => {});
|
|
||||||
vi.spyOn(core, 'setOutput').mockImplementation((_n, _v) => {});
|
|
||||||
vi.spyOn(core, 'debug').mockImplementation((_m) => {});
|
|
||||||
vi.spyOn(core, 'info').mockImplementation((_m) => {});
|
|
||||||
process.env = {
|
process.env = {
|
||||||
...mocks.envs,
|
...mocks.envs,
|
||||||
AWS_ACCESS_KEY_ID: 'CLEANUPTEST',
|
AWS_ACCESS_KEY_ID: 'CLEANUPTEST',
|
||||||
@@ -38,15 +33,35 @@ describe('Configure AWS Credentials cleanup', {}, () => {
|
|||||||
expect(core.exportVariable).toHaveBeenCalledWith('AWS_DEFAULT_REGION', '');
|
expect(core.exportVariable).toHaveBeenCalledWith('AWS_DEFAULT_REGION', '');
|
||||||
expect(core.exportVariable).toHaveBeenCalledWith('AWS_REGION', '');
|
expect(core.exportVariable).toHaveBeenCalledWith('AWS_REGION', '');
|
||||||
});
|
});
|
||||||
|
it('also clears AWS_PROFILE when aws-profile was set', {}, () => {
|
||||||
|
vi.mocked(core.getInput).mockImplementation((name: string) => {
|
||||||
|
if (name === 'aws-profile') return 'my-profile';
|
||||||
|
if (name === 'output-env-credentials') return 'true';
|
||||||
|
return '';
|
||||||
|
});
|
||||||
|
cleanup();
|
||||||
|
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||||
|
expect(core.exportVariable).toHaveBeenCalledTimes(6);
|
||||||
|
expect(core.exportVariable).toHaveBeenCalledWith('AWS_PROFILE', '');
|
||||||
|
});
|
||||||
|
it('skips env cleanup when aws-profile is set without output-env-credentials', {}, () => {
|
||||||
|
vi.mocked(core.getInput).mockImplementation((name: string) => {
|
||||||
|
if (name === 'aws-profile') return 'my-profile';
|
||||||
|
return '';
|
||||||
|
});
|
||||||
|
cleanup();
|
||||||
|
expect(core.setFailed).toHaveBeenCalledTimes(0);
|
||||||
|
expect(core.exportVariable).toHaveBeenCalledTimes(0);
|
||||||
|
});
|
||||||
it('handles errors', {}, () => {
|
it('handles errors', {}, () => {
|
||||||
vi.spyOn(core, 'exportVariable').mockImplementationOnce(() => {
|
vi.mocked(core.exportVariable).mockImplementationOnce(() => {
|
||||||
throw new Error('Test error');
|
throw new Error('Test error');
|
||||||
});
|
});
|
||||||
cleanup();
|
cleanup();
|
||||||
expect(core.setFailed).toHaveBeenCalled();
|
expect(core.setFailed).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
it(`doesn't export credentials as empty env variables if asked not to`, {}, () => {
|
it(`doesn't export credentials as empty env variables if asked not to`, {}, () => {
|
||||||
vi.spyOn(core, 'getInput').mockImplementation(mocks.getInput(mocks.NO_ENV_CREDS_INPUTS));
|
vi.mocked(core.getInput).mockImplementation(mocks.getInput(mocks.NO_ENV_CREDS_INPUTS));
|
||||||
cleanup();
|
cleanup();
|
||||||
expect(core.exportVariable).toHaveBeenCalledTimes(0);
|
expect(core.exportVariable).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|||||||
+205
-2
@@ -1,11 +1,16 @@
|
|||||||
import { beforeEach } from 'node:test';
|
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import { describe, expect, it, vi } from 'vitest';
|
import { fs, vol } from 'memfs';
|
||||||
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||||
import * as helpers from '../src/helpers';
|
import * as helpers from '../src/helpers';
|
||||||
|
|
||||||
|
vi.mock('node:fs');
|
||||||
|
vi.mock('@actions/core');
|
||||||
|
|
||||||
describe('Configure AWS Credentials helpers', {}, () => {
|
describe('Configure AWS Credentials helpers', {}, () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.restoreAllMocks();
|
vi.restoreAllMocks();
|
||||||
|
vi.clearAllMocks();
|
||||||
|
vol.reset();
|
||||||
});
|
});
|
||||||
it('removes brackets from GitHub Actor', {}, () => {
|
it('removes brackets from GitHub Actor', {}, () => {
|
||||||
const actor = 'actor[bot]';
|
const actor = 'actor[bot]';
|
||||||
@@ -23,6 +28,29 @@ describe('Configure AWS Credentials helpers', {}, () => {
|
|||||||
await expect(helpers.retryAndBackoff(fn, false)).rejects.toMatch('i am not retryable');
|
await expect(helpers.retryAndBackoff(fn, false)).rejects.toMatch('i am not retryable');
|
||||||
expect(fn).toHaveBeenCalledTimes(1);
|
expect(fn).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
it('retries and logs with label at info level', {}, async () => {
|
||||||
|
helpers.withsleep(() => Promise.resolve());
|
||||||
|
const fn = vi.fn().mockRejectedValueOnce(new Error('transient')).mockResolvedValueOnce('success');
|
||||||
|
const result = await helpers.retryAndBackoff(fn, true, 3, 0, 50, 'TestOp');
|
||||||
|
expect(result).toBe('success');
|
||||||
|
expect(fn).toHaveBeenCalledTimes(2);
|
||||||
|
expect(core.info).toHaveBeenCalledWith(expect.stringContaining('Retry TestOp: attempt 1 of 3 failed'));
|
||||||
|
helpers.reset();
|
||||||
|
});
|
||||||
|
it('logs max retries reached with label', {}, async () => {
|
||||||
|
helpers.withsleep(() => Promise.resolve());
|
||||||
|
const fn = vi.fn().mockRejectedValue(new Error('persistent'));
|
||||||
|
await expect(helpers.retryAndBackoff(fn, true, 2, 0, 50, 'TestOp')).rejects.toThrow('persistent');
|
||||||
|
expect(core.info).toHaveBeenCalledWith(expect.stringContaining('Retry TestOp: reached max retries (2)'));
|
||||||
|
helpers.reset();
|
||||||
|
});
|
||||||
|
it('retries without a label (backward compat)', {}, async () => {
|
||||||
|
helpers.withsleep(() => Promise.resolve());
|
||||||
|
const fn = vi.fn().mockRejectedValueOnce(new Error('transient')).mockResolvedValueOnce('ok');
|
||||||
|
await helpers.retryAndBackoff(fn, true, 3);
|
||||||
|
expect(core.info).toHaveBeenCalledWith(expect.stringContaining('Retry: attempt 1 of 3 failed'));
|
||||||
|
helpers.reset();
|
||||||
|
});
|
||||||
it('can output creds when told to', {}, () => {
|
it('can output creds when told to', {}, () => {
|
||||||
vi.spyOn(core, 'setOutput').mockImplementation(() => {});
|
vi.spyOn(core, 'setOutput').mockImplementation(() => {});
|
||||||
vi.spyOn(core, 'setSecret').mockImplementation(() => {});
|
vi.spyOn(core, 'setSecret').mockImplementation(() => {});
|
||||||
@@ -61,4 +89,179 @@ describe('Configure AWS Credentials helpers', {}, () => {
|
|||||||
expect(core.setSecret).toHaveBeenCalledTimes(3);
|
expect(core.setSecret).toHaveBeenCalledTimes(3);
|
||||||
expect(core.exportVariable).toHaveBeenCalledTimes(0);
|
expect(core.exportVariable).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('verifies credentials without special characters', {}, () => {
|
||||||
|
expect(helpers.verifyKeys({ AccessKeyId: 'AKIATEST', SecretAccessKey: 'secretkey' })).toBe(true);
|
||||||
|
expect(helpers.verifyKeys({ AccessKeyId: 'AKIA!@#$', SecretAccessKey: 'secret' })).toBe(false);
|
||||||
|
expect(helpers.verifyKeys(undefined)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('translates environment variables', {}, () => {
|
||||||
|
process.env.AWS_REGION = 'us-east-1';
|
||||||
|
process.env.HTTPS_PROXY = 'https://proxy:8080';
|
||||||
|
helpers.translateEnvVariables();
|
||||||
|
expect(process.env['INPUT_AWS-REGION']).toBe('us-east-1');
|
||||||
|
expect(process.env.HTTP_PROXY).toBe('https://proxy:8080');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles getBooleanInput correctly', {}, () => {
|
||||||
|
vi.spyOn(core, 'getInput').mockReturnValue('true');
|
||||||
|
expect(helpers.getBooleanInput('test')).toBe(true);
|
||||||
|
|
||||||
|
vi.spyOn(core, 'getInput').mockReturnValue('false');
|
||||||
|
expect(helpers.getBooleanInput('test')).toBe(false);
|
||||||
|
|
||||||
|
vi.spyOn(core, 'getInput').mockReturnValue('');
|
||||||
|
expect(helpers.getBooleanInput('test', { default: true })).toBe(true);
|
||||||
|
|
||||||
|
vi.spyOn(core, 'getInput').mockReturnValue('invalid');
|
||||||
|
expect(() => helpers.getBooleanInput('test')).toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('clears session token when not provided', {}, () => {
|
||||||
|
vi.spyOn(core, 'setSecret').mockImplementation(() => {});
|
||||||
|
vi.spyOn(core, 'exportVariable').mockImplementation(() => {});
|
||||||
|
process.env.AWS_SESSION_TOKEN = 'old-token';
|
||||||
|
helpers.exportCredentials({ AccessKeyId: 'test', SecretAccessKey: 'test' }, false, true);
|
||||||
|
expect(core.exportVariable).toHaveBeenCalledWith('AWS_SESSION_TOKEN', '');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('filesystem helpers', {}, () => {
|
||||||
|
describe('isSymlink', {}, () => {
|
||||||
|
it('returns true for a symlink', {}, () => {
|
||||||
|
fs.mkdirSync('/dir', { recursive: true });
|
||||||
|
fs.writeFileSync('/dir/target', 'data');
|
||||||
|
fs.symlinkSync('/dir/target', '/dir/link');
|
||||||
|
expect(helpers.isSymlink('/dir/link')).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns false for a regular file', {}, () => {
|
||||||
|
fs.mkdirSync('/dir', { recursive: true });
|
||||||
|
fs.writeFileSync('/dir/file', 'data');
|
||||||
|
expect(helpers.isSymlink('/dir/file')).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns false for a missing path', {}, () => {
|
||||||
|
expect(helpers.isSymlink('/nonexistent')).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('readFileUtf8', {}, () => {
|
||||||
|
it('returns content for a regular file', {}, () => {
|
||||||
|
fs.mkdirSync('/dir', { recursive: true });
|
||||||
|
fs.writeFileSync('/dir/file', 'hello');
|
||||||
|
expect(helpers.readFileUtf8('/dir/file')).toBe('hello');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns null when the file does not exist', {}, () => {
|
||||||
|
fs.mkdirSync('/dir', { recursive: true });
|
||||||
|
expect(helpers.readFileUtf8('/dir/missing')).toBe(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('refuses to read through a symlink at the target', {}, () => {
|
||||||
|
fs.mkdirSync('/dir', { recursive: true });
|
||||||
|
fs.writeFileSync('/dir/secret', 'sensitive');
|
||||||
|
fs.symlinkSync('/dir/secret', '/dir/link');
|
||||||
|
expect(() => helpers.readFileUtf8('/dir/link')).toThrow(/Refusing .* \(.* symbolic link\)/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('refuses to read when the parent directory is a symlink', {}, () => {
|
||||||
|
fs.mkdirSync('/real/.aws', { recursive: true });
|
||||||
|
fs.writeFileSync('/real/.aws/credentials', 'data');
|
||||||
|
fs.mkdirSync('/home', { recursive: true });
|
||||||
|
fs.symlinkSync('/real/.aws', '/home/.aws');
|
||||||
|
expect(() => helpers.readFileUtf8('/home/.aws/credentials')).toThrow(/Refusing .* \(.* symbolic link\)/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('refuses to read when the path is a directory', {}, () => {
|
||||||
|
fs.mkdirSync('/dir/subdir', { recursive: true });
|
||||||
|
expect(() => helpers.readFileUtf8('/dir/subdir')).toThrow(/not a regular file/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it.skipIf(process.platform === 'win32')(
|
||||||
|
'follows the kubelet projected-token symlink chain at /var/run/secrets/*/serviceaccount/token',
|
||||||
|
() => {
|
||||||
|
fs.mkdirSync('/var/run/secrets/eks.amazonaws.com/serviceaccount/..2026_05_28_00_00_00.123', {
|
||||||
|
recursive: true,
|
||||||
|
});
|
||||||
|
fs.writeFileSync(
|
||||||
|
'/var/run/secrets/eks.amazonaws.com/serviceaccount/..2026_05_28_00_00_00.123/token',
|
||||||
|
'jwt-token',
|
||||||
|
);
|
||||||
|
fs.symlinkSync('..2026_05_28_00_00_00.123', '/var/run/secrets/eks.amazonaws.com/serviceaccount/..data');
|
||||||
|
fs.symlinkSync('..data/token', '/var/run/secrets/eks.amazonaws.com/serviceaccount/token');
|
||||||
|
expect(helpers.readFileUtf8('/var/run/secrets/eks.amazonaws.com/serviceaccount/token')).toBe('jwt-token');
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
it.skipIf(process.platform === 'win32')('still refuses symlinks at lookalike paths outside the allowlist', () => {
|
||||||
|
fs.mkdirSync('/var/run/secrets/eks.amazonaws.com/serviceaccount', { recursive: true });
|
||||||
|
fs.writeFileSync('/var/run/secrets/eks.amazonaws.com/serviceaccount/secret', 'jwt-token');
|
||||||
|
fs.symlinkSync(
|
||||||
|
'/var/run/secrets/eks.amazonaws.com/serviceaccount/secret',
|
||||||
|
'/var/run/secrets/eks.amazonaws.com/serviceaccount/token2',
|
||||||
|
);
|
||||||
|
expect(() => helpers.readFileUtf8('/var/run/secrets/eks.amazonaws.com/serviceaccount/token2')).toThrow(
|
||||||
|
/Refusing .* \(.* symbolic link\)/,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('isAllowListed', {}, () => {
|
||||||
|
it.skipIf(process.platform === 'win32')('matches the canonical kubelet projected-token path', () => {
|
||||||
|
expect(helpers.isAllowListed('/var/run/secrets/eks.amazonaws.com/serviceaccount/token')).toBe(true);
|
||||||
|
expect(helpers.isAllowListed('/var/run/secrets/kubernetes.io/serviceaccount/token')).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it.skipIf(process.platform === 'win32')('rejects nested or unrelated paths', () => {
|
||||||
|
expect(helpers.isAllowListed('/var/run/secrets/serviceaccount/token')).toBe(false);
|
||||||
|
expect(helpers.isAllowListed('/var/run/secrets/a/b/serviceaccount/token')).toBe(false);
|
||||||
|
expect(helpers.isAllowListed('/var/run/secrets/eks.amazonaws.com/serviceaccount/token2')).toBe(false);
|
||||||
|
expect(helpers.isAllowListed('/etc/var/run/secrets/foo/serviceaccount/token')).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it.skipIf(process.platform === 'win32')('normalizes path traversal attempts', () => {
|
||||||
|
expect(helpers.isAllowListed('/var/run/secrets/foo/serviceaccount/../../../../etc/passwd')).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('writeFileUtf8', {}, () => {
|
||||||
|
it('writes content with the specified mode', {}, () => {
|
||||||
|
fs.mkdirSync('/dir', { recursive: true });
|
||||||
|
helpers.writeFileUtf8('/dir/file', 'payload', 0o600);
|
||||||
|
expect(fs.readFileSync('/dir/file', 'utf-8')).toBe('payload');
|
||||||
|
expect(fs.statSync('/dir/file').mode & 0o777).toBe(0o600);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('refuses to follow a symlink at the target and leaves the target file untouched', {}, () => {
|
||||||
|
fs.mkdirSync('/dir', { recursive: true });
|
||||||
|
fs.writeFileSync('/dir/target', 'original');
|
||||||
|
fs.symlinkSync('/dir/target', '/dir/link');
|
||||||
|
expect(() => helpers.writeFileUtf8('/dir/link', 'attacker', 0o600)).toThrow(/Refusing .* \(.* symbolic link\)/);
|
||||||
|
expect(fs.readFileSync('/dir/target', 'utf-8')).toBe('original');
|
||||||
|
});
|
||||||
|
|
||||||
|
it.skipIf(process.platform === 'win32')('tightens mode on existing files', () => {
|
||||||
|
fs.mkdirSync('/dir', { recursive: true });
|
||||||
|
fs.writeFileSync('/dir/file', 'old', { mode: 0o644 });
|
||||||
|
helpers.writeFileUtf8('/dir/file', 'new', 0o600);
|
||||||
|
expect(fs.statSync('/dir/file').mode & 0o777).toBe(0o600);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('mkdir', {}, () => {
|
||||||
|
it('is idempotent on a regular directory', {}, () => {
|
||||||
|
helpers.mkdir('/some/nested/dir', 0o700);
|
||||||
|
helpers.mkdir('/some/nested/dir', 0o700);
|
||||||
|
expect(fs.statSync('/some/nested/dir').isDirectory()).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('refuses when the target directory is a symlink', {}, () => {
|
||||||
|
fs.mkdirSync('/real', { recursive: true });
|
||||||
|
fs.mkdirSync('/home', { recursive: true });
|
||||||
|
fs.symlinkSync('/real', '/home/.aws');
|
||||||
|
expect(() => helpers.mkdir('/home/.aws', 0o700)).toThrow(/Refusing .* \(.* symbolic link\)/);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+1164
-48
File diff suppressed because it is too large
Load Diff
@@ -6,6 +6,46 @@ const inputs = {
|
|||||||
'aws-region': 'fake-region-1',
|
'aws-region': 'fake-region-1',
|
||||||
'special-characters-workaround': 'true',
|
'special-characters-workaround': 'true',
|
||||||
},
|
},
|
||||||
|
CUSTOM_TAGS_INVALID_JSON_INPUTS: {
|
||||||
|
'aws-access-key-id': 'MYAWSACCESSKEYID',
|
||||||
|
'aws-secret-access-key': 'MYAWSSECRETACCESSKEY',
|
||||||
|
'role-to-assume': 'arn:aws:iam::111111111111:role/MY-ROLE',
|
||||||
|
'aws-region': 'fake-region-1',
|
||||||
|
'retry-max-attempts': '1',
|
||||||
|
'custom-tags': 'not a json',
|
||||||
|
},
|
||||||
|
CUSTOM_TAGS_ARRAY_INPUTS: {
|
||||||
|
'aws-access-key-id': 'MYAWSACCESSKEYID',
|
||||||
|
'aws-secret-access-key': 'MYAWSSECRETACCESSKEY',
|
||||||
|
'role-to-assume': 'arn:aws:iam::111111111111:role/MY-ROLE',
|
||||||
|
'aws-region': 'fake-region-1',
|
||||||
|
'retry-max-attempts': '1',
|
||||||
|
'custom-tags': '[1, 2, 3]',
|
||||||
|
},
|
||||||
|
CUSTOM_TAGS_RESERVED_KEY_INPUTS: {
|
||||||
|
'aws-access-key-id': 'MYAWSACCESSKEYID',
|
||||||
|
'aws-secret-access-key': 'MYAWSSECRETACCESSKEY',
|
||||||
|
'role-to-assume': 'arn:aws:iam::111111111111:role/MY-ROLE',
|
||||||
|
'aws-region': 'fake-region-1',
|
||||||
|
'retry-max-attempts': '1',
|
||||||
|
'custom-tags': JSON.stringify({ Repository: 'evil-repo' }),
|
||||||
|
},
|
||||||
|
CUSTOM_TAGS_INVALID_KEY_CHARS_INPUTS: {
|
||||||
|
'aws-access-key-id': 'MYAWSACCESSKEYID',
|
||||||
|
'aws-secret-access-key': 'MYAWSSECRETACCESSKEY',
|
||||||
|
'role-to-assume': 'arn:aws:iam::111111111111:role/MY-ROLE',
|
||||||
|
'aws-region': 'fake-region-1',
|
||||||
|
'retry-max-attempts': '1',
|
||||||
|
'custom-tags': JSON.stringify({ 'invalid{key}': 'value' }),
|
||||||
|
},
|
||||||
|
CUSTOM_TAGS_OBJECT_INPUTS: {
|
||||||
|
'aws-access-key-id': 'MYAWSACCESSKEYID',
|
||||||
|
'aws-secret-access-key': 'MYAWSSECRETACCESSKEY',
|
||||||
|
'role-to-assume': 'arn:aws:iam::111111111111:role/MY-ROLE',
|
||||||
|
'aws-region': 'fake-region-1',
|
||||||
|
'retry-max-attempts': '1',
|
||||||
|
'custom-tags': JSON.stringify({ Environment: 'Production', Team: 'DevOps' }),
|
||||||
|
},
|
||||||
IAM_USER_INPUTS: {
|
IAM_USER_INPUTS: {
|
||||||
'aws-access-key-id': 'MYAWSACCESSKEYID',
|
'aws-access-key-id': 'MYAWSACCESSKEYID',
|
||||||
'aws-secret-access-key': 'MYAWSSECRETACCESSKEY',
|
'aws-secret-access-key': 'MYAWSSECRETACCESSKEY',
|
||||||
@@ -43,6 +83,14 @@ const inputs = {
|
|||||||
'output-env-credentials': 'false',
|
'output-env-credentials': 'false',
|
||||||
'output-credentials': 'true',
|
'output-credentials': 'true',
|
||||||
},
|
},
|
||||||
|
IAM_ASSUMEROLE_NO_ENV_INPUTS: {
|
||||||
|
'aws-access-key-id': 'MYAWSACCESSKEYID',
|
||||||
|
'aws-secret-access-key': 'MYAWSSECRETACCESSKEY',
|
||||||
|
'role-to-assume': 'arn:aws:iam::111111111111:role/MY-ROLE',
|
||||||
|
'aws-region': 'fake-region-1',
|
||||||
|
'output-env-credentials': 'false',
|
||||||
|
'output-credentials': 'true',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const envs = {
|
const envs = {
|
||||||
@@ -53,6 +101,13 @@ const envs = {
|
|||||||
GITHUB_SHA: 'MY-COMMIT-ID',
|
GITHUB_SHA: 'MY-COMMIT-ID',
|
||||||
GITHUB_WORKSPACE: '/home/github',
|
GITHUB_WORKSPACE: '/home/github',
|
||||||
GITHUB_ACTIONS: 'true',
|
GITHUB_ACTIONS: 'true',
|
||||||
|
GITHUB_REF: 'refs/pull/42/merge',
|
||||||
|
GITHUB_EVENT_NAME: 'pull_request',
|
||||||
|
GITHUB_RUN_ID: '16412345678',
|
||||||
|
GITHUB_JOB: 'build',
|
||||||
|
GITHUB_BASE_REF: 'main',
|
||||||
|
GITHUB_HEAD_REF: 'feature-branch',
|
||||||
|
GITHUB_TRIGGERING_ACTOR: 'MY-USERNAME[bot]',
|
||||||
};
|
};
|
||||||
|
|
||||||
const outputs = {
|
const outputs = {
|
||||||
|
|||||||
@@ -0,0 +1,804 @@
|
|||||||
|
import * as core from '@actions/core';
|
||||||
|
import { fs, vol } from 'memfs';
|
||||||
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||||
|
import {
|
||||||
|
ensureAwsDirectoryExists,
|
||||||
|
getProfileFilePaths,
|
||||||
|
mergeProfileSection,
|
||||||
|
parseIni,
|
||||||
|
stringifyIni,
|
||||||
|
validateProfileName,
|
||||||
|
writeProfileFiles,
|
||||||
|
} from '../src/profileManager';
|
||||||
|
|
||||||
|
vi.mock('node:fs');
|
||||||
|
vi.mock('@actions/core');
|
||||||
|
|
||||||
|
describe('Profile Manager', {}, () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
vi.restoreAllMocks();
|
||||||
|
vi.clearAllMocks();
|
||||||
|
vol.reset();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('parseIni', {}, () => {
|
||||||
|
it('parses a single section', {}, () => {
|
||||||
|
const result = parseIni('[dev]\naws_access_key_id=AKIA\naws_secret_access_key=secret\n');
|
||||||
|
expect(result.dev).toEqual({ aws_access_key_id: 'AKIA', aws_secret_access_key: 'secret' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('parses multiple sections', {}, () => {
|
||||||
|
const result = parseIni('[dev]\nkey=dev_val\n\n[prod]\nkey=prod_val\n');
|
||||||
|
expect(result.dev.key).toBe('dev_val');
|
||||||
|
expect(result.prod.key).toBe('prod_val');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('skips comments and empty lines', {}, () => {
|
||||||
|
const result = parseIni('# comment\n; another comment\n\n[dev]\nkey=val\n');
|
||||||
|
expect(result.dev).toEqual({ key: 'val' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('trims whitespace around keys and values', {}, () => {
|
||||||
|
const result = parseIni('[dev]\n key = val \n');
|
||||||
|
expect(result.dev.key).toBe('val');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('preserves section names with spaces (e.g. profile prefix)', {}, () => {
|
||||||
|
const result = parseIni('[profile dev]\nregion=us-east-1\n');
|
||||||
|
expect(result['profile dev']).toEqual({ region: 'us-east-1' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('guards against __proto__ section pollution', {}, () => {
|
||||||
|
const result = parseIni('[__proto__]\npolluted=true\n[safe]\nkey=val\n');
|
||||||
|
expect(result.__proto__).not.toHaveProperty('polluted');
|
||||||
|
expect(result.safe).toEqual({ key: 'val' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('guards against __proto__ key pollution', {}, () => {
|
||||||
|
const result = parseIni('[dev]\n__proto__=evil\naws_access_key_id=AKIA\n');
|
||||||
|
expect(result.dev).toEqual({ aws_access_key_id: 'AKIA' });
|
||||||
|
expect(result.dev).not.toHaveProperty('__proto__', 'evil');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles values containing equals signs', {}, () => {
|
||||||
|
const result = parseIni('[dev]\naws_session_token=FwoGZXIvYXdzEBYa/base64==\n');
|
||||||
|
expect(result.dev.aws_session_token).toBe('FwoGZXIvYXdzEBYa/base64==');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles empty values', {}, () => {
|
||||||
|
const result = parseIni('[dev]\ncli_pager=\n');
|
||||||
|
expect(result.dev.cli_pager).toBe('');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns empty object for empty input', {}, () => {
|
||||||
|
expect(parseIni('')).toEqual({});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns empty object for whitespace-only input', {}, () => {
|
||||||
|
expect(parseIni(' \n\n \n')).toEqual({});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles Windows line endings (CRLF)', {}, () => {
|
||||||
|
const result = parseIni('[dev]\r\naws_access_key_id=AKIA\r\naws_secret_access_key=secret\r\n');
|
||||||
|
expect(result.dev).toEqual({ aws_access_key_id: 'AKIA', aws_secret_access_key: 'secret' });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('stringifyIni', {}, () => {
|
||||||
|
it('serializes a single section', {}, () => {
|
||||||
|
const result = stringifyIni({ dev: { key: 'val' } });
|
||||||
|
expect(result).toBe('[dev]\nkey = val\n');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('serializes multiple sections with blank line separator', {}, () => {
|
||||||
|
const result = stringifyIni({ dev: { a: '1' }, prod: { b: '2' } });
|
||||||
|
expect(result).toBe('[dev]\na = 1\n\n[prod]\nb = 2\n');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('round-trips through parseIni', {}, () => {
|
||||||
|
const data = {
|
||||||
|
dev: { aws_access_key_id: 'AKIA', aws_secret_access_key: 'secret' },
|
||||||
|
'profile prod': { region: 'us-west-2' },
|
||||||
|
};
|
||||||
|
const roundTripped = parseIni(stringifyIni(data));
|
||||||
|
expect(roundTripped).toEqual(data);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles empty data object', {}, () => {
|
||||||
|
const result = stringifyIni({});
|
||||||
|
expect(result).toBe('\n');
|
||||||
|
expect(parseIni(result)).toEqual({});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles section with no keys', {}, () => {
|
||||||
|
const result = stringifyIni({ dev: {} });
|
||||||
|
expect(result).toBe('[dev]\n');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('validateProfileName', {}, () => {
|
||||||
|
it('accepts valid profile names', {}, () => {
|
||||||
|
expect(() => validateProfileName('dev')).not.toThrow();
|
||||||
|
expect(() => validateProfileName('production')).not.toThrow();
|
||||||
|
expect(() => validateProfileName('my-profile-123')).not.toThrow();
|
||||||
|
expect(() => validateProfileName('default')).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rejects empty profile names', {}, () => {
|
||||||
|
expect(() => validateProfileName('')).toThrow('aws-profile must not be empty');
|
||||||
|
expect(() => validateProfileName(' ')).toThrow('aws-profile must not be empty');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rejects profile names with whitespace', {}, () => {
|
||||||
|
expect(() => validateProfileName('my profile')).toThrow('aws-profile must not contain whitespace');
|
||||||
|
expect(() => validateProfileName('dev\ntest')).toThrow('aws-profile must not contain whitespace');
|
||||||
|
expect(() => validateProfileName('prod\tenv')).toThrow('aws-profile must not contain whitespace');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rejects profile names with brackets', {}, () => {
|
||||||
|
expect(() => validateProfileName('dev[test]')).toThrow('aws-profile must not contain brackets');
|
||||||
|
expect(() => validateProfileName('[profile]')).toThrow('aws-profile must not contain brackets');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rejects profile names with path separators', {}, () => {
|
||||||
|
expect(() => validateProfileName('dev/test')).toThrow('aws-profile must not contain path separators');
|
||||||
|
expect(() => validateProfileName('dev\\test')).toThrow('aws-profile must not contain path separators');
|
||||||
|
expect(() => validateProfileName('../etc/passwd')).toThrow('aws-profile must not contain path separators');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getProfileFilePaths', {}, () => {
|
||||||
|
it('returns default paths when env vars not set', {}, () => {
|
||||||
|
delete process.env.AWS_SHARED_CREDENTIALS_FILE;
|
||||||
|
delete process.env.AWS_CONFIG_FILE;
|
||||||
|
|
||||||
|
const paths = getProfileFilePaths();
|
||||||
|
|
||||||
|
expect(paths.credentials).toMatch(/\.aws[/\\]credentials$/);
|
||||||
|
expect(paths.config).toMatch(/\.aws[/\\]config$/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('respects AWS_SHARED_CREDENTIALS_FILE env var', {}, () => {
|
||||||
|
process.env.AWS_SHARED_CREDENTIALS_FILE = '/custom/path/credentials';
|
||||||
|
process.env.AWS_CONFIG_FILE = '/custom/path/config';
|
||||||
|
|
||||||
|
const paths = getProfileFilePaths();
|
||||||
|
|
||||||
|
expect(paths.credentials).toBe('/custom/path/credentials');
|
||||||
|
expect(paths.config).toBe('/custom/path/config');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('ensureAwsDirectoryExists', {}, () => {
|
||||||
|
it('creates directory if it does not exist', {}, () => {
|
||||||
|
const filePath = '/home/runner/.aws/credentials';
|
||||||
|
|
||||||
|
ensureAwsDirectoryExists(filePath);
|
||||||
|
|
||||||
|
expect(fs.existsSync('/home/runner/.aws')).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not error if directory already exists', {}, () => {
|
||||||
|
const filePath = '/home/runner/.aws/credentials';
|
||||||
|
|
||||||
|
fs.mkdirSync('/home/runner/.aws', { recursive: true });
|
||||||
|
|
||||||
|
expect(() => ensureAwsDirectoryExists(filePath)).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('creates nested directories', {}, () => {
|
||||||
|
const filePath = '/home/runner/custom/path/.aws/credentials';
|
||||||
|
|
||||||
|
ensureAwsDirectoryExists(filePath);
|
||||||
|
|
||||||
|
expect(fs.existsSync('/home/runner/custom/path/.aws')).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('mergeProfileSection', {}, () => {
|
||||||
|
it('creates new file with profile section', {}, () => {
|
||||||
|
const filePath = '/home/runner/.aws/credentials';
|
||||||
|
fs.mkdirSync('/home/runner/.aws', { recursive: true });
|
||||||
|
|
||||||
|
mergeProfileSection(
|
||||||
|
filePath,
|
||||||
|
'dev',
|
||||||
|
{
|
||||||
|
aws_access_key_id: 'AKIAIOSFODNN7EXAMPLE',
|
||||||
|
aws_secret_access_key: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
|
const content = fs.readFileSync(filePath, 'utf-8');
|
||||||
|
const parsed = parseIni(content);
|
||||||
|
|
||||||
|
expect(parsed.dev).toBeDefined();
|
||||||
|
expect(parsed.dev.aws_access_key_id).toBe('AKIAIOSFODNN7EXAMPLE');
|
||||||
|
expect(parsed.dev.aws_secret_access_key).toBe('wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('merges with existing profiles', {}, () => {
|
||||||
|
const filePath = '/home/runner/.aws/credentials';
|
||||||
|
fs.mkdirSync('/home/runner/.aws', { recursive: true });
|
||||||
|
|
||||||
|
// Create initial profile
|
||||||
|
mergeProfileSection(
|
||||||
|
filePath,
|
||||||
|
'dev',
|
||||||
|
{
|
||||||
|
aws_access_key_id: 'AKIAIOSFODNN7EXAMPLE',
|
||||||
|
aws_secret_access_key: 'devSecretKey',
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Add second profile
|
||||||
|
mergeProfileSection(
|
||||||
|
filePath,
|
||||||
|
'prod',
|
||||||
|
{
|
||||||
|
aws_access_key_id: 'AKIAPRODEXAMPLE',
|
||||||
|
aws_secret_access_key: 'prodSecretKey',
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
|
const content = fs.readFileSync(filePath, 'utf-8');
|
||||||
|
const parsed = parseIni(content);
|
||||||
|
|
||||||
|
expect(parsed.dev).toBeDefined();
|
||||||
|
expect(parsed.dev.aws_access_key_id).toBe('AKIAIOSFODNN7EXAMPLE');
|
||||||
|
expect(parsed.prod).toBeDefined();
|
||||||
|
expect(parsed.prod.aws_access_key_id).toBe('AKIAPRODEXAMPLE');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('overwrites existing profile with same name', {}, () => {
|
||||||
|
const filePath = '/home/runner/.aws/credentials';
|
||||||
|
fs.mkdirSync('/home/runner/.aws', { recursive: true });
|
||||||
|
|
||||||
|
// Create initial profile
|
||||||
|
mergeProfileSection(
|
||||||
|
filePath,
|
||||||
|
'dev',
|
||||||
|
{
|
||||||
|
aws_access_key_id: 'OLD_KEY',
|
||||||
|
aws_secret_access_key: 'oldSecretKey',
|
||||||
|
aws_session_token: 'oldSessionToken',
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Overwrite with new credentials
|
||||||
|
mergeProfileSection(
|
||||||
|
filePath,
|
||||||
|
'dev',
|
||||||
|
{
|
||||||
|
aws_access_key_id: 'NEW_KEY',
|
||||||
|
aws_secret_access_key: 'newSecretKey',
|
||||||
|
aws_session_token: 'newSessionToken',
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
|
||||||
|
const content = fs.readFileSync(filePath, 'utf-8');
|
||||||
|
const parsed = parseIni(content);
|
||||||
|
|
||||||
|
expect(parsed.dev.aws_access_key_id).toBe('NEW_KEY');
|
||||||
|
expect(parsed.dev.aws_secret_access_key).toBe('newSecretKey');
|
||||||
|
expect(parsed.dev.aws_session_token).toBe('newSessionToken');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('overwriting a profile removes stale keys', {}, () => {
|
||||||
|
const filePath = '/home/runner/.aws/credentials';
|
||||||
|
fs.mkdirSync('/home/runner/.aws', { recursive: true });
|
||||||
|
|
||||||
|
// Create profile with session token
|
||||||
|
mergeProfileSection(
|
||||||
|
filePath,
|
||||||
|
'dev',
|
||||||
|
{
|
||||||
|
aws_access_key_id: 'AKIA',
|
||||||
|
aws_secret_access_key: 'secret',
|
||||||
|
aws_session_token: 'old-token',
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Overwrite without session token
|
||||||
|
mergeProfileSection(
|
||||||
|
filePath,
|
||||||
|
'dev',
|
||||||
|
{
|
||||||
|
aws_access_key_id: 'AKIA2',
|
||||||
|
aws_secret_access_key: 'secret2',
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
|
||||||
|
const content = fs.readFileSync(filePath, 'utf-8');
|
||||||
|
const parsed = parseIni(content);
|
||||||
|
|
||||||
|
expect(parsed.dev.aws_access_key_id).toBe('AKIA2');
|
||||||
|
expect(parsed.dev.aws_secret_access_key).toBe('secret2');
|
||||||
|
expect(parsed.dev.aws_session_token).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles empty existing file', {}, () => {
|
||||||
|
const filePath = '/home/runner/.aws/credentials';
|
||||||
|
fs.mkdirSync('/home/runner/.aws', { recursive: true });
|
||||||
|
fs.writeFileSync(filePath, '', { mode: 0o600 });
|
||||||
|
|
||||||
|
mergeProfileSection(
|
||||||
|
filePath,
|
||||||
|
'dev',
|
||||||
|
{
|
||||||
|
aws_access_key_id: 'AKIA',
|
||||||
|
aws_secret_access_key: 'secret',
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
|
const content = fs.readFileSync(filePath, 'utf-8');
|
||||||
|
const parsed = parseIni(content);
|
||||||
|
|
||||||
|
expect(parsed.dev.aws_access_key_id).toBe('AKIA');
|
||||||
|
expect(parsed.dev.aws_secret_access_key).toBe('secret');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('errors if profile name already exists but overwrite flag is false', {}, () => {
|
||||||
|
const filePath = '/home/runner/.aws/credentials';
|
||||||
|
fs.mkdirSync('/home/runner/.aws', { recursive: true });
|
||||||
|
|
||||||
|
// Create initial profile
|
||||||
|
mergeProfileSection(
|
||||||
|
filePath,
|
||||||
|
'dev',
|
||||||
|
{
|
||||||
|
aws_access_key_id: 'OLD_KEY',
|
||||||
|
aws_secret_access_key: 'oldSecretKey',
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Overwrite with new credentials
|
||||||
|
expect(() =>
|
||||||
|
mergeProfileSection(
|
||||||
|
filePath,
|
||||||
|
'dev',
|
||||||
|
{
|
||||||
|
aws_access_key_id: 'NEW_KEY',
|
||||||
|
aws_secret_access_key: 'newSecretKey',
|
||||||
|
aws_session_token: 'sessionToken',
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
),
|
||||||
|
).toThrow(
|
||||||
|
`Profile with name "dev" already exists. Please use the overwrite-aws-profile input if you want to overwrite existing profiles.`,
|
||||||
|
);
|
||||||
|
|
||||||
|
const content = fs.readFileSync(filePath, 'utf-8');
|
||||||
|
const parsed = parseIni(content);
|
||||||
|
|
||||||
|
expect(parsed.dev.aws_access_key_id).toBe('OLD_KEY');
|
||||||
|
expect(parsed.dev.aws_secret_access_key).toBe('oldSecretKey');
|
||||||
|
expect(parsed.dev.aws_session_token).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('writeProfileFiles', {}, () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
delete process.env.AWS_SHARED_CREDENTIALS_FILE;
|
||||||
|
delete process.env.AWS_CONFIG_FILE;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('writes credentials and config for new profile', {}, () => {
|
||||||
|
writeProfileFiles(
|
||||||
|
'dev',
|
||||||
|
{
|
||||||
|
AccessKeyId: 'AKIAIOSFODNN7EXAMPLE',
|
||||||
|
SecretAccessKey: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',
|
||||||
|
SessionToken: 'FwoGZXIvYXdzEBYaDEXAMPLE',
|
||||||
|
},
|
||||||
|
'us-east-1',
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Check credentials file
|
||||||
|
const credsPath = getProfileFilePaths().credentials;
|
||||||
|
const credContent = fs.readFileSync(credsPath, 'utf-8');
|
||||||
|
const credParsed = parseIni(credContent);
|
||||||
|
|
||||||
|
expect(credParsed.dev).toBeDefined();
|
||||||
|
expect(credParsed.dev.aws_access_key_id).toBe('AKIAIOSFODNN7EXAMPLE');
|
||||||
|
expect(credParsed.dev.aws_secret_access_key).toBe('wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY');
|
||||||
|
expect(credParsed.dev.aws_session_token).toBe('FwoGZXIvYXdzEBYaDEXAMPLE');
|
||||||
|
|
||||||
|
// Check config file
|
||||||
|
const configPath = getProfileFilePaths().config;
|
||||||
|
const configContent = fs.readFileSync(configPath, 'utf-8');
|
||||||
|
const configParsed = parseIni(configContent);
|
||||||
|
|
||||||
|
expect(configParsed['profile dev']).toBeDefined();
|
||||||
|
expect(configParsed['profile dev'].region).toBe('us-east-1');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('uses correct section naming for default profile', {}, () => {
|
||||||
|
writeProfileFiles(
|
||||||
|
'default',
|
||||||
|
{
|
||||||
|
AccessKeyId: 'AKIAIOSFODNN7EXAMPLE',
|
||||||
|
SecretAccessKey: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',
|
||||||
|
},
|
||||||
|
'us-west-2',
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Check credentials file uses [default]
|
||||||
|
const credsPath = getProfileFilePaths().credentials;
|
||||||
|
const credContent = fs.readFileSync(credsPath, 'utf-8');
|
||||||
|
const credParsed = parseIni(credContent);
|
||||||
|
|
||||||
|
expect(credParsed.default).toBeDefined();
|
||||||
|
expect(credParsed['profile default']).toBeUndefined();
|
||||||
|
|
||||||
|
// Check config file uses [default] (not [profile default])
|
||||||
|
const configPath = getProfileFilePaths().config;
|
||||||
|
const configContent = fs.readFileSync(configPath, 'utf-8');
|
||||||
|
const configParsed = parseIni(configContent);
|
||||||
|
|
||||||
|
expect(configParsed.default).toBeDefined();
|
||||||
|
expect(configParsed['profile default']).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('supports multiple profiles', {}, () => {
|
||||||
|
// Write first profile
|
||||||
|
writeProfileFiles(
|
||||||
|
'dev',
|
||||||
|
{
|
||||||
|
AccessKeyId: 'AKIADEV',
|
||||||
|
SecretAccessKey: 'devSecret',
|
||||||
|
},
|
||||||
|
'us-east-1',
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Write second profile
|
||||||
|
writeProfileFiles(
|
||||||
|
'prod',
|
||||||
|
{
|
||||||
|
AccessKeyId: 'AKIAPROD',
|
||||||
|
SecretAccessKey: 'prodSecret',
|
||||||
|
SessionToken: 'prodToken',
|
||||||
|
},
|
||||||
|
'us-west-2',
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Verify both profiles exist
|
||||||
|
const credsPath = getProfileFilePaths().credentials;
|
||||||
|
const credContent = fs.readFileSync(credsPath, 'utf-8');
|
||||||
|
const credParsed = parseIni(credContent);
|
||||||
|
|
||||||
|
expect(credParsed.dev).toBeDefined();
|
||||||
|
expect(credParsed.prod).toBeDefined();
|
||||||
|
expect(credParsed.dev.aws_access_key_id).toBe('AKIADEV');
|
||||||
|
expect(credParsed.prod.aws_access_key_id).toBe('AKIAPROD');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles credentials without session token', {}, () => {
|
||||||
|
writeProfileFiles(
|
||||||
|
'dev',
|
||||||
|
{
|
||||||
|
AccessKeyId: 'AKIAIOSFODNN7EXAMPLE',
|
||||||
|
SecretAccessKey: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',
|
||||||
|
},
|
||||||
|
'us-east-1',
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
|
const credsPath = getProfileFilePaths().credentials;
|
||||||
|
const credContent = fs.readFileSync(credsPath, 'utf-8');
|
||||||
|
const credParsed = parseIni(credContent);
|
||||||
|
|
||||||
|
expect(credParsed.dev.aws_access_key_id).toBe('AKIAIOSFODNN7EXAMPLE');
|
||||||
|
expect(credParsed.dev.aws_secret_access_key).toBe('wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY');
|
||||||
|
expect(credParsed.dev.aws_session_token).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('throws error for invalid profile name', {}, () => {
|
||||||
|
expect(() =>
|
||||||
|
writeProfileFiles(
|
||||||
|
'invalid profile',
|
||||||
|
{
|
||||||
|
AccessKeyId: 'AKIA',
|
||||||
|
SecretAccessKey: 'secret',
|
||||||
|
},
|
||||||
|
'us-east-1',
|
||||||
|
false,
|
||||||
|
),
|
||||||
|
).toThrow('Failed to write AWS profile');
|
||||||
|
expect(() =>
|
||||||
|
writeProfileFiles(
|
||||||
|
'invalid profile',
|
||||||
|
{
|
||||||
|
AccessKeyId: 'AKIA',
|
||||||
|
SecretAccessKey: 'secret',
|
||||||
|
},
|
||||||
|
'us-east-1',
|
||||||
|
false,
|
||||||
|
),
|
||||||
|
).toThrow('whitespace');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('respects custom file paths from env vars', {}, () => {
|
||||||
|
process.env.AWS_SHARED_CREDENTIALS_FILE = '/custom/credentials';
|
||||||
|
process.env.AWS_CONFIG_FILE = '/custom/config';
|
||||||
|
|
||||||
|
fs.mkdirSync('/custom', { recursive: true });
|
||||||
|
|
||||||
|
writeProfileFiles(
|
||||||
|
'dev',
|
||||||
|
{
|
||||||
|
AccessKeyId: 'AKIA',
|
||||||
|
SecretAccessKey: 'secret',
|
||||||
|
},
|
||||||
|
'us-east-1',
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(fs.existsSync('/custom/credentials')).toBe(true);
|
||||||
|
expect(fs.existsSync('/custom/config')).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('logs info messages', {}, () => {
|
||||||
|
writeProfileFiles(
|
||||||
|
'dev',
|
||||||
|
{
|
||||||
|
AccessKeyId: 'AKIA',
|
||||||
|
SecretAccessKey: 'secret',
|
||||||
|
},
|
||||||
|
'us-east-1',
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(core.info).toHaveBeenCalledWith('Writing credentials to profile: dev');
|
||||||
|
expect(core.info).toHaveBeenCalledWith('Writing config to profile: dev');
|
||||||
|
expect(core.info).toHaveBeenCalledWith('✓ Successfully configured AWS profile: dev');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('preserves pre-existing unrelated profiles in credentials file', {}, () => {
|
||||||
|
const credsPath = getProfileFilePaths().credentials;
|
||||||
|
fs.mkdirSync(require('node:path').dirname(credsPath), { recursive: true });
|
||||||
|
fs.writeFileSync(
|
||||||
|
credsPath,
|
||||||
|
'[personal]\naws_access_key_id=AKIAPERSONAL\naws_secret_access_key=personalSecret\naws_session_token=personalToken\n',
|
||||||
|
);
|
||||||
|
|
||||||
|
writeProfileFiles('dev', { AccessKeyId: 'AKIADEV', SecretAccessKey: 'devSecret' }, 'us-east-1', false);
|
||||||
|
|
||||||
|
const content = fs.readFileSync(credsPath, 'utf-8');
|
||||||
|
const parsed = parseIni(content);
|
||||||
|
|
||||||
|
// Pre-existing profile must be fully intact
|
||||||
|
expect(parsed.personal).toEqual({
|
||||||
|
aws_access_key_id: 'AKIAPERSONAL',
|
||||||
|
aws_secret_access_key: 'personalSecret',
|
||||||
|
aws_session_token: 'personalToken',
|
||||||
|
});
|
||||||
|
// New profile also present
|
||||||
|
expect(parsed.dev.aws_access_key_id).toBe('AKIADEV');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('preserves pre-existing config with extra keys', {}, () => {
|
||||||
|
const configPath = getProfileFilePaths().config;
|
||||||
|
fs.mkdirSync(require('node:path').dirname(configPath), { recursive: true });
|
||||||
|
fs.writeFileSync(configPath, '[profile personal]\nregion=eu-west-1\noutput=json\ncli_pager=\n');
|
||||||
|
|
||||||
|
writeProfileFiles('dev', { AccessKeyId: 'AKIA', SecretAccessKey: 'secret' }, 'us-east-1', false);
|
||||||
|
|
||||||
|
const content = fs.readFileSync(configPath, 'utf-8');
|
||||||
|
const parsed = parseIni(content);
|
||||||
|
|
||||||
|
expect(parsed['profile personal']).toEqual({
|
||||||
|
region: 'eu-west-1',
|
||||||
|
output: 'json',
|
||||||
|
cli_pager: '',
|
||||||
|
});
|
||||||
|
expect(parsed['profile dev'].region).toBe('us-east-1');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('preserves pre-existing default profile when writing a named profile', {}, () => {
|
||||||
|
const credsPath = getProfileFilePaths().credentials;
|
||||||
|
fs.mkdirSync(require('node:path').dirname(credsPath), { recursive: true });
|
||||||
|
fs.writeFileSync(credsPath, '[default]\naws_access_key_id=AKIADEFAULT\naws_secret_access_key=defaultSecret\n');
|
||||||
|
|
||||||
|
writeProfileFiles('dev', { AccessKeyId: 'AKIADEV', SecretAccessKey: 'devSecret' }, 'us-west-2', false);
|
||||||
|
|
||||||
|
const content = fs.readFileSync(credsPath, 'utf-8');
|
||||||
|
const parsed = parseIni(content);
|
||||||
|
|
||||||
|
expect(parsed.default).toEqual({
|
||||||
|
aws_access_key_id: 'AKIADEFAULT',
|
||||||
|
aws_secret_access_key: 'defaultSecret',
|
||||||
|
});
|
||||||
|
expect(parsed.dev.aws_access_key_id).toBe('AKIADEV');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('comments in pre-existing files are stripped on round-trip', {}, () => {
|
||||||
|
const credsPath = getProfileFilePaths().credentials;
|
||||||
|
fs.mkdirSync(require('node:path').dirname(credsPath), { recursive: true });
|
||||||
|
fs.writeFileSync(
|
||||||
|
credsPath,
|
||||||
|
'# My important comment\n[personal]\naws_access_key_id=AKIA\naws_secret_access_key=secret\n',
|
||||||
|
);
|
||||||
|
|
||||||
|
writeProfileFiles('dev', { AccessKeyId: 'AKIADEV', SecretAccessKey: 'devSecret' }, 'us-east-1', false);
|
||||||
|
|
||||||
|
const content = fs.readFileSync(credsPath, 'utf-8') as string;
|
||||||
|
|
||||||
|
// Comment is lost (known trade-off), but profile data is preserved
|
||||||
|
expect(content).not.toContain('# My important comment');
|
||||||
|
const parsed = parseIni(content);
|
||||||
|
expect(parsed.personal.aws_access_key_id).toBe('AKIA');
|
||||||
|
expect(parsed.dev.aws_access_key_id).toBe('AKIADEV');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('writes empty section when credentials object has no keys', {}, () => {
|
||||||
|
writeProfileFiles('dev', {}, 'us-east-1', false);
|
||||||
|
|
||||||
|
const credsPath = getProfileFilePaths().credentials;
|
||||||
|
const credContent = fs.readFileSync(credsPath, 'utf-8');
|
||||||
|
const credParsed = parseIni(credContent);
|
||||||
|
|
||||||
|
// Section exists but has no credential keys
|
||||||
|
expect(credParsed.dev).toEqual({});
|
||||||
|
|
||||||
|
// Config still gets region
|
||||||
|
const configPath = getProfileFilePaths().config;
|
||||||
|
const configContent = fs.readFileSync(configPath, 'utf-8');
|
||||||
|
const configParsed = parseIni(configContent);
|
||||||
|
expect(configParsed['profile dev'].region).toBe('us-east-1');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('resolves credentials and config paths independently from env vars', {}, () => {
|
||||||
|
process.env.AWS_SHARED_CREDENTIALS_FILE = '/custom-creds/credentials';
|
||||||
|
// AWS_CONFIG_FILE is NOT set — should use default path
|
||||||
|
|
||||||
|
fs.mkdirSync('/custom-creds', { recursive: true });
|
||||||
|
|
||||||
|
writeProfileFiles('dev', { AccessKeyId: 'AKIA', SecretAccessKey: 'secret' }, 'us-east-1', false);
|
||||||
|
|
||||||
|
expect(fs.existsSync('/custom-creds/credentials')).toBe(true);
|
||||||
|
// Config file should be at the default path (under homedir)
|
||||||
|
const defaultConfigPath = require('node:path').join(require('node:os').homedir(), '.aws', 'config');
|
||||||
|
expect(fs.existsSync(defaultConfigPath)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('produces AWS CLI-compatible INI output (golden file)', {}, () => {
|
||||||
|
writeProfileFiles(
|
||||||
|
'dev',
|
||||||
|
{
|
||||||
|
AccessKeyId: 'AKIAIOSFODNN7EXAMPLE',
|
||||||
|
SecretAccessKey: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',
|
||||||
|
SessionToken: 'FwoGZXIvYXdzEBYaDEXAMPLE',
|
||||||
|
},
|
||||||
|
'us-east-1',
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
|
const credsPath = getProfileFilePaths().credentials;
|
||||||
|
const credContent = fs.readFileSync(credsPath, 'utf-8');
|
||||||
|
|
||||||
|
const configPath = getProfileFilePaths().config;
|
||||||
|
const configContent = fs.readFileSync(configPath, 'utf-8');
|
||||||
|
|
||||||
|
// Verify exact byte-for-byte format matching AWS CLI style:
|
||||||
|
// - [section] header on its own line
|
||||||
|
// - key = value with spaces around =
|
||||||
|
// - LF line endings, trailing newline
|
||||||
|
expect(credContent).toBe(
|
||||||
|
'[dev]\n' +
|
||||||
|
'aws_access_key_id = AKIAIOSFODNN7EXAMPLE\n' +
|
||||||
|
'aws_secret_access_key = wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY\n' +
|
||||||
|
'aws_session_token = FwoGZXIvYXdzEBYaDEXAMPLE\n',
|
||||||
|
);
|
||||||
|
expect(configContent).toBe('[profile dev]\n' + 'region = us-east-1\n');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('golden file for multi-profile output', {}, () => {
|
||||||
|
writeProfileFiles('dev', { AccessKeyId: 'AKIADEV', SecretAccessKey: 'devSecret' }, 'us-east-1', false);
|
||||||
|
writeProfileFiles(
|
||||||
|
'prod',
|
||||||
|
{ AccessKeyId: 'AKIAPROD', SecretAccessKey: 'prodSecret', SessionToken: 'prodToken' },
|
||||||
|
'us-west-2',
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
|
const credsPath = getProfileFilePaths().credentials;
|
||||||
|
const credContent = fs.readFileSync(credsPath, 'utf-8');
|
||||||
|
|
||||||
|
const configPath = getProfileFilePaths().config;
|
||||||
|
const configContent = fs.readFileSync(configPath, 'utf-8');
|
||||||
|
|
||||||
|
expect(credContent).toBe(
|
||||||
|
'[dev]\n' +
|
||||||
|
'aws_access_key_id = AKIADEV\n' +
|
||||||
|
'aws_secret_access_key = devSecret\n' +
|
||||||
|
'\n' +
|
||||||
|
'[prod]\n' +
|
||||||
|
'aws_access_key_id = AKIAPROD\n' +
|
||||||
|
'aws_secret_access_key = prodSecret\n' +
|
||||||
|
'aws_session_token = prodToken\n',
|
||||||
|
);
|
||||||
|
expect(configContent).toBe(
|
||||||
|
'[profile dev]\n' + 'region = us-east-1\n' + '\n' + '[profile prod]\n' + 'region = us-west-2\n',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('symlink hardening', {}, () => {
|
||||||
|
const credsPath = '/home/user/.aws/credentials';
|
||||||
|
const configPath = '/home/user/.aws/config';
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
process.env.AWS_SHARED_CREDENTIALS_FILE = credsPath;
|
||||||
|
process.env.AWS_CONFIG_FILE = configPath;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('mergeProfileSection refuses when the credentials path is a symlink and leaves the target unchanged', {}, () => {
|
||||||
|
fs.mkdirSync('/home/user/.aws', { recursive: true });
|
||||||
|
fs.mkdirSync('/etc', { recursive: true });
|
||||||
|
fs.writeFileSync('/etc/passwd', 'root:x:0:0::/root:/bin/sh');
|
||||||
|
fs.symlinkSync('/etc/passwd', credsPath);
|
||||||
|
|
||||||
|
expect(() => mergeProfileSection(credsPath, 'dev', { aws_access_key_id: 'AKIA' }, true)).toThrow(
|
||||||
|
/Refusing .* \(.* symbolic link\)/,
|
||||||
|
);
|
||||||
|
expect(fs.readFileSync('/etc/passwd', 'utf-8')).toBe('root:x:0:0::/root:/bin/sh');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('mergeProfileSection refuses when the config path is a symlink', {}, () => {
|
||||||
|
fs.mkdirSync('/home/user/.aws', { recursive: true });
|
||||||
|
fs.mkdirSync('/etc', { recursive: true });
|
||||||
|
fs.writeFileSync('/etc/sensitive', 'do not overwrite');
|
||||||
|
fs.symlinkSync('/etc/sensitive', configPath);
|
||||||
|
|
||||||
|
expect(() => mergeProfileSection(configPath, 'profile dev', { region: 'us-east-1' }, true)).toThrow(
|
||||||
|
/Refusing .* \(.* symbolic link\)/,
|
||||||
|
);
|
||||||
|
expect(fs.readFileSync('/etc/sensitive', 'utf-8')).toBe('do not overwrite');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ensureAwsDirectoryExists refuses when ~/.aws is a symlink', {}, () => {
|
||||||
|
fs.mkdirSync('/real-target', { recursive: true });
|
||||||
|
fs.mkdirSync('/home/user', { recursive: true });
|
||||||
|
fs.symlinkSync('/real-target', '/home/user/.aws');
|
||||||
|
|
||||||
|
expect(() => ensureAwsDirectoryExists(credsPath)).toThrow(/Refusing .* \(.* symbolic link\)/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('writeProfileFiles refuses to overwrite a pre-existing symlink at the credentials path', {}, () => {
|
||||||
|
fs.mkdirSync('/home/user/.aws', { recursive: true });
|
||||||
|
fs.mkdirSync('/etc', { recursive: true });
|
||||||
|
fs.writeFileSync('/etc/passwd', 'root:x:0:0::/root:/bin/sh');
|
||||||
|
fs.symlinkSync('/etc/passwd', credsPath);
|
||||||
|
|
||||||
|
expect(() =>
|
||||||
|
writeProfileFiles('dev', { AccessKeyId: 'AKIA', SecretAccessKey: 'secret' }, 'us-east-1', true),
|
||||||
|
).toThrow(/Refusing .* \(.* symbolic link\)/);
|
||||||
|
|
||||||
|
expect(fs.lstatSync(credsPath).isSymbolicLink()).toBe(true);
|
||||||
|
expect(fs.readFileSync('/etc/passwd', 'utf-8')).toBe('root:x:0:0::/root:/bin/sh');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('happy path still writes both files with mode 0o600 when no symlinks are present', {}, () => {
|
||||||
|
writeProfileFiles('dev', { AccessKeyId: 'AKIA', SecretAccessKey: 'secret' }, 'us-east-1', false);
|
||||||
|
|
||||||
|
expect(fs.statSync(credsPath).mode & 0o777).toBe(0o600);
|
||||||
|
expect(fs.statSync(configPath).mode & 0o777).toBe(0o600);
|
||||||
|
expect(fs.lstatSync(credsPath).isSymbolicLink()).toBe(false);
|
||||||
|
expect(fs.lstatSync(configPath).isSymbolicLink()).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
+3
-2
@@ -3,7 +3,7 @@
|
|||||||
"allowUnreachableCode": false,
|
"allowUnreachableCode": false,
|
||||||
"allowUnusedLabels": false,
|
"allowUnusedLabels": false,
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"exactOptionalPropertyTypes": false,
|
"exactOptionalPropertyTypes": true,
|
||||||
"noFallthroughCasesInSwitch": true,
|
"noFallthroughCasesInSwitch": true,
|
||||||
"noImplicitOverride": true,
|
"noImplicitOverride": true,
|
||||||
"noImplicitReturns": true,
|
"noImplicitReturns": true,
|
||||||
@@ -23,7 +23,8 @@
|
|||||||
"target": "ES2020",
|
"target": "ES2020",
|
||||||
"noErrorTruncation": true,
|
"noErrorTruncation": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"rootDir": "src"
|
"rootDir": "src",
|
||||||
|
"skipLibCheck": true
|
||||||
},
|
},
|
||||||
"include": ["src/**/*.ts"],
|
"include": ["src/**/*.ts"],
|
||||||
"exclude": ["test/**/*.ts"]
|
"exclude": ["test/**/*.ts"]
|
||||||
|
|||||||
Reference in New Issue
Block a user