@@ -28,6 +28,9 @@ import (
2828 "github.com/spf13/cobra"
2929 corev1 "k8s.io/api/core/v1"
3030
31+ "github.com/fluxcd/pkg/auth"
32+ "github.com/fluxcd/pkg/auth/aws"
33+ authutils "github.com/fluxcd/pkg/auth/utils"
3134 "github.com/fluxcd/pkg/git"
3235 "github.com/fluxcd/pkg/git/gogit"
3336
@@ -62,9 +65,12 @@ command will perform an upgrade if needed.`,
6265 # Run bootstrap for a Git repository with a private key and password
6366 flux bootstrap git --url=ssh://git@example.com/repository.git --private-key-file=<path/to/private.key> --password=<password> --path=clusters/my-cluster
6467
65- # Run bootstrap for a Git repository on AWS CodeCommit
68+ # Run bootstrap for a Git repository on AWS CodeCommit using SSH
6669 flux bootstrap git --url=ssh://<SSH-Key-ID>@git-codecommit.<region>.amazonaws.com/v1/repos/<repository> --private-key-file=<path/to/private.key> --password=<SSH-passphrase> --path=clusters/my-cluster
6770
71+ # Run bootstrap for a Git repository on AWS CodeCommit using HTTPS with IAM credentials
72+ flux bootstrap git --url=https://git-codecommit.<region>.amazonaws.com/v1/repos/<repository> --path=clusters/my-cluster
73+
6874 # Run bootstrap for a Git repository on Azure Devops
6975 flux bootstrap git --url=ssh://git@ssh.dev.azure.com/v3/<org>/<project>/<repository> --private-key-file=<path/to/rsa-sha2-private.key> --ssh-hostkey-algos=rsa-sha2-512,rsa-sha2-256 --path=clusters/my-cluster
7076
@@ -109,6 +115,7 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error {
109115 bootstrapArgs .tokenAuth = true
110116 }
111117
118+ var gitProvider string
112119 gitPassword := os .Getenv (gitPasswordEnvVar )
113120 if gitPassword != "" && gitArgs .password == "" {
114121 gitArgs .password = gitPassword
@@ -131,8 +138,12 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error {
131138 return err
132139 }
133140
141+ ctx , cancel := context .WithTimeout (context .Background (), rootArgs .timeout )
142+ defer cancel ()
143+
134144 if strings .Contains (repositoryURL .Hostname (), "git-codecommit" ) && strings .Contains (repositoryURL .Hostname (), "amazonaws.com" ) {
135- if repositoryURL .Scheme == string (git .SSH ) {
145+ // https://docs.aws.amazon.com/codecommit/latest/userguide/auth-and-access-control.html
146+ if repositoryURL .Scheme == string (git .SSH ) { // IAM user + SSH
136147 if repositoryURL .User == nil {
137148 return fmt .Errorf ("invalid AWS CodeCommit url: ssh username should be specified in the url" )
138149 }
@@ -142,14 +153,18 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error {
142153 if bootstrapArgs .privateKeyFile == "" {
143154 return fmt .Errorf ("private key file is required for bootstrapping against AWS CodeCommit using ssh" )
144155 }
156+ } else if repositoryURL .Scheme == string (git .HTTPS ) && ! bootstrapArgs .tokenAuth { // IAM role + HTTPS
157+ creds , err := authutils .GetGitCredentials (ctx , "aws" , auth .WithGitURL (* repositoryURL ))
158+ if err != nil {
159+ return fmt .Errorf ("failed to get AWS CodeCommit IAM git credentials: %w" , err )
160+ }
161+ gitArgs .username = creds .Username
162+ gitArgs .password = creds .Password
163+ bootstrapArgs .tokenAuth = true
164+ gitProvider = aws .ProviderName
145165 }
146- if repositoryURL .Scheme == string (git .HTTPS ) && ! bootstrapArgs .tokenAuth {
147- return fmt .Errorf ("--token-auth=true must be specified for using an HTTPS AWS CodeCommit url" )
148- }
149- }
150166
151- ctx , cancel := context .WithTimeout (context .Background (), rootArgs .timeout )
152- defer cancel ()
167+ }
153168
154169 kubeClient , err := utils .KubeClient (kubeconfigArgs , kubeclientOptions )
155170 if err != nil {
@@ -297,6 +312,9 @@ func bootstrapGitCmdRun(cmd *cobra.Command, args []string) error {
297312 ManifestFile : sync .MakeDefaultOptions ().ManifestFile ,
298313 RecurseSubmodules : bootstrapArgs .recurseSubmodules ,
299314 }
315+ if gitProvider != "" {
316+ syncOpts .Provider = gitProvider
317+ }
300318
301319 entityList , err := bootstrap .LoadEntityListFromPath (bootstrapArgs .gpgKeyRingPath )
302320 if err != nil {
0 commit comments