[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"\u002Fp\u002Fgithub-aws-oidc-secure-connection":3},{"id":4,"title":5,"aws":6,"body":7,"categories":903,"createdAt":906,"description":907,"difficulty":908,"extension":909,"image":910,"links":912,"meta":927,"navigation":6,"path":928,"seo":929,"sitemap":930,"stem":934,"tags":935,"toc":6,"type":941,"updatedAt":933,"__hash__":942},"p\u002Fp\u002Fgithub-aws-oidc-secure-connection.md","Connect Your GitHub Repository to AWS Securely Using OIDC",true,{"type":8,"value":9,"toc":891},"minimark",[10,14,19,22,45,49,52,57,128,132,541,545,552,784,792,802,806,829,833,836,856,860,863,887],[11,12,13],"p",{},"OpenID Connect (OIDC) enables GitHub Actions to authenticate with AWS without relying on long-lived credentials. By generating short-lived, temporary tokens for each workflow run, OIDC strengthens security and simplifies credential management, eliminating the need to store sensitive secrets in your repository.",[15,16,18],"h2",{"id":17},"why-use-oidc-with-github-actions-and-aws","Why Use OIDC with GitHub Actions and AWS?",[11,20,21],{},"OIDC is the most secure and recommended method for authenticating GitHub Actions with AWS. It removes the risk of exposing AWS access keys by replacing them with automatically generated, short-lived tokens. This approach minimizes credential exposure while ensuring seamless, secure access to AWS resources.",[23,24,25,33,39],"ul",{},[26,27,28,32],"li",{},[29,30,31],"strong",{},"Enhanced Security:"," Eliminates the need to store long-lived AWS access keys or secrets in your repository.",[26,34,35,38],{},[29,36,37],{},"Automation Token Rotation:"," Tokens are automatically generated and rotated for each workflow run, reducing the risk of credential leakage.",[26,40,41,44],{},[29,42,43],{},"Granular Access Control:"," You can define fine-grained permissions for each workflow or repository,ensuring the principle of least privilege.",[15,46,48],{"id":47},"configure-the-oidc-provider-in-aws","Configure the OIDC Provider in AWS",[11,50,51],{},"To allow AWS to trust GitHub as an identity provider, you need to create an IAM OIDC identity provider in your AWS account.",[53,54,56],"h3",{"id":55},"create-the-oidc-provider","Create the OIDC Provider",[58,59,61,66,90,94,123],"steps",{"level":60},"4",[62,63,65],"h4",{"id":64},"navigate-to-iam","Navigate to IAM",[11,67,68,69,81,82,85,86,89],{},"Go to the ",[70,71,75,76,80],"a",{"href":72,"rel":73},"https:\u002F\u002Fconsole.aws.amazon.com\u002Fiam\u002F",[74],"nofollow","IAM Console ",[77,78],"icon",{"name":79},"i-logos-aws-iam"," ",", select ",[29,83,84],{},"Identity providers",", and click ",[29,87,88],{},"Add provider",".",[62,91,93],{"id":92},"configure-the-provider-details","Configure the Provider details",[23,95,96,105,115],{},[26,97,98,101,102,89],{},[29,99,100],{},"Provider type:"," Select ",[29,103,104],{},"OpenID Connect",[26,106,107,110,111,89],{},[29,108,109],{},"Provider URL:"," Enter ",[112,113,114],"code",{},"https:\u002F\u002Ftoken.actions.githubusercontent.com",[26,116,117,110,120,89],{},[29,118,119],{},"Audience:",[112,121,122],{},"sts.amazonaws.com",[11,124,125,126,89],{},"Click ",[29,127,88],{},[53,129,131],{"id":130},"create-an-iam-role-for-github-actions","Create an IAM Role for GitHub Actions",[58,133,134,138,148,193,198,202,209,213,223,510,530,534],{"level":60},[62,135,137],{"id":136},"create-a-role","Create a Role",[11,139,140,141,144,145,89],{},"Go to ",[29,142,143],{},"Roles"," and click ",[29,146,147],{},"Create role",[23,149,150,158,164,170,180],{},[26,151,152,101,155,89],{},[29,153,154],{},"Trusted entity type:",[29,156,157],{},"Web identity",[26,159,160,163],{},[29,161,162],{},"Identity provider:"," Choose the provider you just created (token.actions.githubusercontent.com).",[26,165,166,101,168,89],{},[29,167,119],{},[112,169,122],{},[26,171,172,175,176,179],{},[29,173,174],{},"GitHub repository:"," If you either want to allow only a specific repository or every repository of your account\u002Forganization (default ",[112,177,178],{},"*"," for all repositories).",[26,181,182,185,186,188,189,192],{},[29,183,184],{},"GitHub branch:"," If you either want to allow only a specific branch or every branch to be able to access your AWS account (default ",[112,187,178],{}," for all branches, I recommend to use ",[112,190,191],{},"main"," to enforce least privilege).",[194,195],"img",{"alt":196,"src":197},"Web Identity Details on AWS Console","p\u002Fgithub-aws-oidc-secure-connection\u002Faws_console_iam_web_identity.jpg",[62,199,201],{"id":200},"attach-permissions","Attach Permissions",[11,203,204,205,208],{},"Attach the necessary policies to the role (",[112,206,207],{},"AdministratorAccess"," for temporary testing, or a custom policy with least-privilege permissions for production).",[62,210,212],{"id":211},"review-the-role","Review the Role",[11,214,215,216,218,219,222],{},"Restrict which GitHub repositories and branches can assume this role. I recommend you explicitly specify the branches you want to allow, ",[112,217,191],{}," and ",[112,220,221],{},"dev"," for example. You should get a similar policy as below:",[224,225,230],"pre",{"className":226,"code":227,"language":228,"meta":229,"style":229},"language-json shiki shiki-themes min-light min-light plastic","{\n    \"Version\": \"2012-10-17\",\n    \"Statement\": [\n        {\n            \"Effect\": \"Allow\",\n            \"Action\": \"sts:AssumeRoleWithWebIdentity\",\n            \"Principal\": {\n                \"Federated\": \"arn:aws:iam::\u003CACCOUNT_ID>:oidc-provider\u002Ftoken.actions.githubusercontent.com\"\n            },\n            \"Condition\": {\n                \"StringEquals\": {\n                    \"token.actions.githubusercontent.com:aud\": \"sts.amazonaws.com\"\n                },\n                \"StringLike\": {\n                    \"token.actions.githubusercontent.com:sub\": [\n                      \"\u003CREPOSITORY>\"\n                    ]\n                }\n            }\n        }\n    ]\n}\n","json","",[112,231,232,241,272,287,293,315,336,351,372,380,394,408,427,435,449,463,474,480,486,492,498,504],{"__ignoreMap":229},[233,234,237],"span",{"class":235,"line":236},"line",1,[233,238,240],{"class":239},"slmz-","{\n",[233,242,244,248,252,255,259,263,267,269],{"class":235,"line":243},2,[233,245,247],{"class":246},"siOgq","    \"",[233,249,251],{"class":250},"sN-14","Version",[233,253,254],{"class":246},"\"",[233,256,258],{"class":257},"skl3q",":",[233,260,262],{"class":261},"sB6Cb"," \"",[233,264,266],{"class":265},"sw9Es","2012-10-17",[233,268,254],{"class":261},[233,270,271],{"class":257},",\n",[233,273,275,277,280,282,284],{"class":235,"line":274},3,[233,276,247],{"class":246},[233,278,279],{"class":250},"Statement",[233,281,254],{"class":246},[233,283,258],{"class":257},[233,285,286],{"class":239}," [\n",[233,288,290],{"class":235,"line":289},4,[233,291,292],{"class":239},"        {\n",[233,294,296,299,302,304,306,308,311,313],{"class":235,"line":295},5,[233,297,298],{"class":246},"            \"",[233,300,301],{"class":250},"Effect",[233,303,254],{"class":246},[233,305,258],{"class":257},[233,307,262],{"class":261},[233,309,310],{"class":265},"Allow",[233,312,254],{"class":261},[233,314,271],{"class":257},[233,316,318,320,323,325,327,329,332,334],{"class":235,"line":317},6,[233,319,298],{"class":246},[233,321,322],{"class":250},"Action",[233,324,254],{"class":246},[233,326,258],{"class":257},[233,328,262],{"class":261},[233,330,331],{"class":265},"sts:AssumeRoleWithWebIdentity",[233,333,254],{"class":261},[233,335,271],{"class":257},[233,337,339,341,344,346,348],{"class":235,"line":338},7,[233,340,298],{"class":246},[233,342,343],{"class":250},"Principal",[233,345,254],{"class":246},[233,347,258],{"class":257},[233,349,350],{"class":239}," {\n",[233,352,354,357,360,362,364,366,369],{"class":235,"line":353},8,[233,355,356],{"class":246},"                \"",[233,358,359],{"class":250},"Federated",[233,361,254],{"class":246},[233,363,258],{"class":257},[233,365,262],{"class":261},[233,367,368],{"class":265},"arn:aws:iam::\u003CACCOUNT_ID>:oidc-provider\u002Ftoken.actions.githubusercontent.com",[233,370,371],{"class":261},"\"\n",[233,373,375,378],{"class":235,"line":374},9,[233,376,377],{"class":239},"            }",[233,379,271],{"class":257},[233,381,383,385,388,390,392],{"class":235,"line":382},10,[233,384,298],{"class":246},[233,386,387],{"class":250},"Condition",[233,389,254],{"class":246},[233,391,258],{"class":257},[233,393,350],{"class":239},[233,395,397,399,402,404,406],{"class":235,"line":396},11,[233,398,356],{"class":246},[233,400,401],{"class":250},"StringEquals",[233,403,254],{"class":246},[233,405,258],{"class":257},[233,407,350],{"class":239},[233,409,411,414,417,419,421,423,425],{"class":235,"line":410},12,[233,412,413],{"class":246},"                    \"",[233,415,416],{"class":250},"token.actions.githubusercontent.com:aud",[233,418,254],{"class":246},[233,420,258],{"class":257},[233,422,262],{"class":261},[233,424,122],{"class":265},[233,426,371],{"class":261},[233,428,430,433],{"class":235,"line":429},13,[233,431,432],{"class":239},"                }",[233,434,271],{"class":257},[233,436,438,440,443,445,447],{"class":235,"line":437},14,[233,439,356],{"class":246},[233,441,442],{"class":250},"StringLike",[233,444,254],{"class":246},[233,446,258],{"class":257},[233,448,350],{"class":239},[233,450,452,454,457,459,461],{"class":235,"line":451},15,[233,453,413],{"class":246},[233,455,456],{"class":250},"token.actions.githubusercontent.com:sub",[233,458,254],{"class":246},[233,460,258],{"class":257},[233,462,286],{"class":239},[233,464,466,469,472],{"class":235,"line":465},16,[233,467,468],{"class":261},"                      \"",[233,470,471],{"class":265},"\u003CREPOSITORY>",[233,473,371],{"class":261},[233,475,477],{"class":235,"line":476},17,[233,478,479],{"class":239},"                    ]\n",[233,481,483],{"class":235,"line":482},18,[233,484,485],{"class":239},"                }\n",[233,487,489],{"class":235,"line":488},19,[233,490,491],{"class":239},"            }\n",[233,493,495],{"class":235,"line":494},20,[233,496,497],{"class":239},"        }\n",[233,499,501],{"class":235,"line":500},21,[233,502,503],{"class":239},"    ]\n",[233,505,507],{"class":235,"line":506},22,[233,508,509],{"class":239},"}\n",[511,512,513],"warning",{},[11,514,515,518,519,521,522,525,526,529],{},[112,516,517],{},"\u003CACCOUNT_ID>"," should be your AWS account ID and ",[112,520,471],{}," the Github repository. The repository must be in the form ",[112,523,524],{},"repo:ORG-NAME\u002FREPO-NAME:ref:refs:\u002Fheads\u002FBRANCH"," or ",[112,527,528],{},"repo:ORG-NAME\u002FREPO-NAME:*"," to allow any branch.",[62,531,533],{"id":532},"name-and-create-the-role","Name and Create the Role",[11,535,536,537,540],{},"Name the role ",[112,538,539],{},"GitHubActionsRole"," and create it.",[15,542,544],{"id":543},"create-a-github-actions-workflow","Create a GitHub Actions workflow",[11,546,547,548,551],{},"Once your AWS Account is set up, let's create a workflow file ",[112,549,550],{},".github\u002Fworkflows\u002Fdeploy.yml"," in your repository as follows:",[224,553,558],{"className":554,"code":555,"filename":556,"language":557,"meta":229,"style":229},"language-yml shiki shiki-themes min-light min-light plastic","name: Verify AWS OIDC\n\non:\n  push:\n    branches:\n      - main\n\npermissions:\n  id-token: write # This is required for GitHub to request a JWT\n  contents: read\n\njobs:\n  deploy:\n    runs-on: ubuntu-latest\n    \n    steps:\n      - name: Checkout code\n        uses: actions\u002Fcheckout@v5\n\n      - name: Configure AWS credentials\n        uses: aws-actions\u002Fconfigure-aws-credentials@v4\n        with:\n          role-to-assume: arn:aws:iam::\u003CACCOUNT_ID>:role\u002FGitHubActionsRole\n          aws-region: us-east-1\n\n      - name: Verify AWS identity\n        run: aws sts get-caller-identity\n","deploy.yml","yml",[112,559,560,571,576,585,592,599,607,611,618,632,642,646,653,660,670,675,682,693,703,707,718,727,734,745,756,761,773],{"__ignoreMap":229},[233,561,562,566,568],{"class":235,"line":236},[233,563,565],{"class":564},"s6W6U","name",[233,567,258],{"class":246},[233,569,570],{"class":265}," Verify AWS OIDC\n",[233,572,573],{"class":235,"line":243},[233,574,575],{"emptyLinePlaceholder":6},"\n",[233,577,578,582],{"class":235,"line":274},[233,579,581],{"class":580},"sAhIg","on",[233,583,584],{"class":246},":\n",[233,586,587,590],{"class":235,"line":289},[233,588,589],{"class":564},"  push",[233,591,584],{"class":246},[233,593,594,597],{"class":235,"line":295},[233,595,596],{"class":564},"    branches",[233,598,584],{"class":246},[233,600,601,604],{"class":235,"line":317},[233,602,603],{"class":239},"      - ",[233,605,606],{"class":265},"main\n",[233,608,609],{"class":235,"line":338},[233,610,575],{"emptyLinePlaceholder":6},[233,612,613,616],{"class":235,"line":353},[233,614,615],{"class":564},"permissions",[233,617,584],{"class":246},[233,619,620,623,625,628],{"class":235,"line":374},[233,621,622],{"class":564},"  id-token",[233,624,258],{"class":246},[233,626,627],{"class":265}," write",[233,629,631],{"class":630},"sQchT"," # This is required for GitHub to request a JWT\n",[233,633,634,637,639],{"class":235,"line":382},[233,635,636],{"class":564},"  contents",[233,638,258],{"class":246},[233,640,641],{"class":265}," read\n",[233,643,644],{"class":235,"line":396},[233,645,575],{"emptyLinePlaceholder":6},[233,647,648,651],{"class":235,"line":410},[233,649,650],{"class":564},"jobs",[233,652,584],{"class":246},[233,654,655,658],{"class":235,"line":429},[233,656,657],{"class":564},"  deploy",[233,659,584],{"class":246},[233,661,662,665,667],{"class":235,"line":437},[233,663,664],{"class":564},"    runs-on",[233,666,258],{"class":246},[233,668,669],{"class":265}," ubuntu-latest\n",[233,671,672],{"class":235,"line":451},[233,673,674],{"class":239},"    \n",[233,676,677,680],{"class":235,"line":465},[233,678,679],{"class":564},"    steps",[233,681,584],{"class":246},[233,683,684,686,688,690],{"class":235,"line":476},[233,685,603],{"class":239},[233,687,565],{"class":564},[233,689,258],{"class":246},[233,691,692],{"class":265}," Checkout code\n",[233,694,695,698,700],{"class":235,"line":482},[233,696,697],{"class":564},"        uses",[233,699,258],{"class":246},[233,701,702],{"class":265}," actions\u002Fcheckout@v5\n",[233,704,705],{"class":235,"line":488},[233,706,575],{"emptyLinePlaceholder":6},[233,708,709,711,713,715],{"class":235,"line":494},[233,710,603],{"class":239},[233,712,565],{"class":564},[233,714,258],{"class":246},[233,716,717],{"class":265}," Configure AWS credentials\n",[233,719,720,722,724],{"class":235,"line":500},[233,721,697],{"class":564},[233,723,258],{"class":246},[233,725,726],{"class":265}," aws-actions\u002Fconfigure-aws-credentials@v4\n",[233,728,729,732],{"class":235,"line":506},[233,730,731],{"class":564},"        with",[233,733,584],{"class":246},[233,735,737,740,742],{"class":235,"line":736},23,[233,738,739],{"class":564},"          role-to-assume",[233,741,258],{"class":246},[233,743,744],{"class":265}," arn:aws:iam::\u003CACCOUNT_ID>:role\u002FGitHubActionsRole\n",[233,746,748,751,753],{"class":235,"line":747},24,[233,749,750],{"class":564},"          aws-region",[233,752,258],{"class":246},[233,754,755],{"class":265}," us-east-1\n",[233,757,759],{"class":235,"line":758},25,[233,760,575],{"emptyLinePlaceholder":6},[233,762,764,766,768,770],{"class":235,"line":763},26,[233,765,603],{"class":239},[233,767,565],{"class":564},[233,769,258],{"class":246},[233,771,772],{"class":265}," Verify AWS identity\n",[233,774,776,779,781],{"class":235,"line":775},27,[233,777,778],{"class":564},"        run",[233,780,258],{"class":246},[233,782,783],{"class":265}," aws sts get-caller-identity\n",[511,785,786],{},[11,787,788,789,791],{},"Replace ",[112,790,517],{}," with your AWS account ID.",[793,794,795],"note",{},[11,796,797,798,801],{},"The ",[112,799,800],{},"aws-actions\u002Fconfigure-aws-credentials"," action handles the OIDC token exchange and configures the AWS CLI.",[53,803,805],{"id":804},"test-the-workflow","Test the workflow",[58,807,808,812,818,822],{"level":60},[62,809,811],{"id":810},"commit-and-push","Commit and Push",[11,813,814,815,817],{},"Commit the workflow file to the ",[112,816,191],{}," branch. The workflow will run automatically.",[62,819,821],{"id":820},"check-the-output","Check the Output",[11,823,824,825,828],{},"In the GitHub Actions log, you should see the output of ",[112,826,827],{},"aws sts get-caller-identity",", confirming that the workflow has successfully assumed the IAM role previously created.",[15,830,832],{"id":831},"best-practices","Best Practices",[11,834,835],{},"Now that you have successfully linked your AWS account to your GitHub repository, be sure to respect these best practices:",[23,837,838,844,850],{},[26,839,840,843],{},[29,841,842],{},"Least Privilege:"," Always attach the minimum required permissions to the IAM role.",[26,845,846,849],{},[29,847,848],{},"Branch Protection:"," Use conditions to restrict which branches or tags can assume the role.",[26,851,852,855],{},[29,853,854],{},"Audit Logs:"," Monitor AWS CloudTrail and GitHub Actions logs for unusual activity.",[15,857,859],{"id":858},"troubleshooting","Troubleshooting",[11,861,862],{},"If you encounter any issues when running your workflow, it might come from:",[23,864,865,871,877],{},[26,866,867,870],{},[29,868,869],{},"Permission Errors:"," Ensure the IAM role has the correct trust policy and permissions.",[26,872,873,876],{},[29,874,875],{},"Workflow Failures:"," Check the GitHub Actions log for detailed error messages.",[26,878,879,882,883,886],{},[29,880,881],{},"Token Issues:"," Verify that the ",[112,884,885],{},"id-token: write"," permission is set and the OIDC provider is correctly configured in AWS.",[888,889,890],"style",{},"html pre.shiki code .s6W6U, html code.shiki .s6W6U{--shiki-light:#D32F2F;--shiki-default:#D32F2F;--shiki-dark:#E5C07B}html pre.shiki code .siOgq, html code.shiki .siOgq{--shiki-light:#D32F2F;--shiki-default:#D32F2F;--shiki-dark:#A9B2C3}html pre.shiki code .sw9Es, html code.shiki .sw9Es{--shiki-light:#22863A;--shiki-default:#22863A;--shiki-dark:#98C379}html pre.shiki code .sAhIg, html code.shiki .sAhIg{--shiki-light:#1976D2;--shiki-default:#1976D2;--shiki-dark:#56B6C2}html pre.shiki code .slmz-, html code.shiki .slmz-{--shiki-light:#24292EFF;--shiki-default:#24292EFF;--shiki-dark:#A9B2C3}html pre.shiki code .sQchT, html code.shiki .sQchT{--shiki-light:#C2C3C5;--shiki-light-font-style:inherit;--shiki-default:#C2C3C5;--shiki-default-font-style:inherit;--shiki-dark:#5F6672;--shiki-dark-font-style:italic}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sN-14, html code.shiki .sN-14{--shiki-light:#D32F2F;--shiki-default:#D32F2F;--shiki-dark:#C6CCD7}html pre.shiki code .skl3q, html code.shiki .skl3q{--shiki-light:#212121;--shiki-default:#212121;--shiki-dark:#A9B2C3}html pre.shiki code .sB6Cb, html code.shiki .sB6Cb{--shiki-light:#22863A;--shiki-default:#22863A;--shiki-dark:#A9B2C3}",{"title":229,"searchDepth":243,"depth":243,"links":892},[893,894,898,901,902],{"id":17,"depth":243,"text":18},{"id":47,"depth":243,"text":48,"children":895},[896,897],{"id":55,"depth":274,"text":56},{"id":130,"depth":274,"text":131},{"id":543,"depth":243,"text":544,"children":899},[900],{"id":804,"depth":274,"text":805},{"id":831,"depth":243,"text":832},{"id":858,"depth":243,"text":859},[904,905],"DevOps","Security","2025-11-03","Securely connect your GitHub repository to AWS with OpenID Connect (OIDC), replacing long-lived credentials with short-lived rotated tokens.","L200","md",{"src":911},"\u002Fcovers\u002Fgithub-aws-oidc-secure-connection.jpg",{"tools":913,"aws":918,"externals":923},[914],{"label":915,"icon":916,"to":917},"Github","logos:github-icon","\u002Fr\u002Fgithub",[919],{"label":920,"icon":921,"to":922},"IAM","aws:iam","\u002Faws?services=iam",[924],{"label":104,"to":925,"target":926},"https:\u002F\u002Fdocs.github.com\u002Fen\u002Factions\u002Fconcepts\u002Fsecurity\u002Fopenid-connect","_blank",{},"\u002Fp\u002Fgithub-aws-oidc-secure-connection",{"title":5,"description":907},{"loc":928,"images":931,"lastmod":933},[932],{"loc":197},"2025-11-25","p\u002Fgithub-aws-oidc-secure-connection",[936,937,938,939,940],"Automation","CI\u002FCD","Deployment","JWT","OIDC","Guide","rP5RluZY6XdNO2QqZqiksZZmouaQyGj-fUlKJze_mpo"]