Skip to content

Commit f62fa80

Browse files
committed
[RFC-0010] Add default-service-account for lockdown
Add --default-service-account flag for multi-tenant workload identity lockdown support. This flag sets the default service account name to be used when .spec.serviceAccountName is not specified in resources. Signed-off-by: cappyzawa <[email protected]>
1 parent efa9671 commit f62fa80

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ require (
2020
github.com/fluxcd/pkg/apis/acl v0.8.0
2121
github.com/fluxcd/pkg/apis/event v0.18.0
2222
github.com/fluxcd/pkg/apis/meta v1.18.0
23-
github.com/fluxcd/pkg/auth v0.21.0
23+
github.com/fluxcd/pkg/auth v0.26.0
2424
github.com/fluxcd/pkg/cache v0.10.0
2525
github.com/fluxcd/pkg/git v0.35.0
2626
github.com/fluxcd/pkg/git/gogit v0.38.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ github.com/fluxcd/pkg/apis/event v0.18.0 h1:PNbWk9gvX8gMIi6VsJapnuDO+giLEeY+6olL
134134
github.com/fluxcd/pkg/apis/event v0.18.0/go.mod h1:7S/DGboLolfbZ6stO6dcDhG1SfkPWQ9foCULvbiYpiA=
135135
github.com/fluxcd/pkg/apis/meta v1.18.0 h1:ACHrMIjlcioE9GKS7NGk62KX4NshqNewr8sBwMcXABs=
136136
github.com/fluxcd/pkg/apis/meta v1.18.0/go.mod h1:97l3hTwBpJbXBY+wetNbqrUsvES8B1jGioKcBUxmqd8=
137-
github.com/fluxcd/pkg/auth v0.21.0 h1:ckAQqP12wuptXEkMY18SQKWEY09m9e6yI0mEMsDV15M=
138-
github.com/fluxcd/pkg/auth v0.21.0/go.mod h1:MXmpsXT97c874HCw5hnfqFUP7TsG8/Ss1vFrk8JccfM=
137+
github.com/fluxcd/pkg/auth v0.26.0 h1:jw128zPI4aRSvkGbFfAQcFNF3oK58P4rDdKIpj2/7yM=
138+
github.com/fluxcd/pkg/auth v0.26.0/go.mod h1:YEAHpBFuW5oLlH9ekuJaQdnJ2Q3A7Ny8kha3WY7QMnY=
139139
github.com/fluxcd/pkg/cache v0.10.0 h1:M+OGDM4da1cnz7q+sZSBtkBJHpiJsLnKVmR9OdMWxEY=
140140
github.com/fluxcd/pkg/cache v0.10.0/go.mod h1:pPXRzQUDQagsCniuOolqVhnAkbNgYOg8d2cTliPs7ME=
141141
github.com/fluxcd/pkg/git v0.35.0 h1:mAauhsdfxNW4yQdXviVlvcN/uCGGG0+6p5D1+HFZI9w=

internal/source/git.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,10 @@ func getAuthOpts(ctx context.Context, c client.Client, repo *sourcev1.GitReposit
204204
switch provider := repo.GetProvider(); provider {
205205
case sourcev1.GitProviderAzure: // If AWS or GCP are added in the future they can be added here separated by a comma.
206206
getCreds = func() (*authutils.GitCredentials, error) {
207-
var opts []auth.Option
207+
opts := []auth.Option{
208+
auth.WithClient(c),
209+
auth.WithServiceAccountNamespace(srcOpts.objNamespace),
210+
}
208211

209212
if srcOpts.tokenCache != nil {
210213
involvedObject := cache.InvolvedObject{

main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,15 @@ func main() {
9393
watchOptions helper.WatchOptions
9494
concurrent int
9595
tokenCacheOptions cache.TokenFlags
96+
defaultServiceAccount string
9697
)
9798

9899
flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
99100
flag.StringVar(&eventsAddr, "events-addr", "", "The address of the events receiver.")
100101
flag.StringVar(&healthAddr, "health-addr", ":9440", "The address the health endpoint binds to.")
101102
flag.IntVar(&concurrent, "concurrent", 4, "The number of concurrent resource reconciles.")
103+
flag.StringVar(&defaultServiceAccount, auth.ControllerFlagDefaultServiceAccount,
104+
"", "Default service account to use for workload identity when not specified in resources.")
102105
flag.StringSliceVar(&git.KexAlgos, "ssh-kex-algos", []string{},
103106
"The list of key exchange algorithms to use for ssh connections, arranged from most preferred to the least.")
104107
flag.StringSliceVar(&git.HostKeyAlgos, "ssh-hostkey-algos", []string{},
@@ -115,6 +118,10 @@ func main() {
115118

116119
flag.Parse()
117120

121+
if defaultServiceAccount != "" {
122+
auth.SetDefaultServiceAccount(defaultServiceAccount)
123+
}
124+
118125
logger.SetLogger(logger.NewLogger(logOptions))
119126

120127
err := featureGates.WithLogger(setupLog).

0 commit comments

Comments
 (0)