-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC-007] Implement GitHub app authentication for git repositories in IAC #780
base: main
Are you sure you want to change the base?
Conversation
go.mod
Outdated
replace github.com/fluxcd/source-controller/api => github.com/dipti-pai/source-controller/api v0.0.0-20241022192612-2ada07176114 | ||
|
||
replace github.com/fluxcd/pkg/auth => github.com/dipti-pai/pkg/auth v0.0.0-20241024052802-53e4364eab6a | ||
|
||
replace github.com/fluxcd/pkg/git => github.com/dipti-pai/pkg/git v0.0.0-20241024052802-53e4364eab6a | ||
|
||
replace github.com/fluxcd/pkg/git/gogit => github.com/dipti-pai/pkg/git/gogit v0.0.0-20241024052802-53e4364eab6a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reminder to remove these before merging.
… IAC - Controller change to use the GitHub authentication information specified in Git Repository's `.spec.secretRef` to create the auth options to authenticate to git repositories when the `provider` field is set to `github`, - Tests for new `github` provider field in IAC - Updated docs to use GitHub Apps for authentication in image-automation-controller. Signed-off-by: Dipti Pai <[email protected]>
0ee43c8
to
67837db
Compare
opts.ProviderOpts = &git.ProviderOptions{ | ||
Name: sourcev1.GitProviderAzure, | ||
AzureOpts: []azure.OptFunc{ | ||
azure.WithAzureDevOpsScope(), | ||
}, | ||
} | ||
case sourcev1.GitProviderGitHub: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the SC issue described in fluxcd/source-controller#1647 (comment), it would be good to perform a provider validation here too. In this case, we have a typed error already
var ErrInvalidSourceConfiguration = errors.New("invalid source configuration") |
We can return an error with proper context, saying that the referred GitRepository's provider configuration is invalid. Wrapping the typed error with the context should allow the reader of the errors to determine that it should result in stalled state, with the context intact. Refer similar code in
image-automation-controller/internal/source/source.go
Lines 102 to 108 in 5b945f7
if obj.Spec.SourceRef.Kind != sourcev1.GitRepositoryKind { | |
return nil, fmt.Errorf("source kind '%s' not supported: %w", obj.Spec.SourceRef.Kind, ErrInvalidSourceConfiguration) | |
} | |
if obj.Spec.GitSpec == nil { | |
return nil, fmt.Errorf("source kind '%s' necessitates field .spec.git: %w", sourcev1.GitRepositoryKind, ErrInvalidSourceConfiguration) | |
} |
and see how the reconciler interprets it
image-automation-controller/internal/controller/imageupdateautomation_controller.go
Lines 354 to 358 in 5b945f7
if errors.Is(err, source.ErrInvalidSourceConfiguration) { | |
conditions.MarkStalled(obj, imagev1.InvalidSourceConfigReason, "%s", err) | |
result, retErr = ctrl.Result{}, nil | |
return | |
} |
Since we have a watch for GitRepository in
image-automation-controller/internal/controller/imageupdateautomation_controller.go
Lines 140 to 143 in 5b945f7
Watches( | |
&sourcev1.GitRepository{}, | |
handler.EnqueueRequestsFromMapFunc(r.automationsForGitRepo), | |
builder.WithPredicates(sourceConfigChangePredicate{}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also consider an update to the same issue in source-controller fluxcd/source-controller#1647 (comment).
I believe the same validations can be done within getAuthOpts()
.
gitrepository.spec.secretRef
to create the auth options to authenticate to git repositories when thegitrepository.spec.provider
field is set togithub
,github
provider field in IAC