Skip to content

Commit

Permalink
Added new authtype gcpksa
Browse files Browse the repository at this point in the history
  • Loading branch information
droot committed Dec 6, 2023
1 parent c0cc4fd commit 87cc242
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 22 deletions.
6 changes: 3 additions & 3 deletions cmd/oci-sync/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ import (
var flImage = flag.String("image", util.EnvString(reconcilermanager.OciSyncImage, ""),
"the OCI image repository for the package")
var flAuth = flag.String("auth", util.EnvString(reconcilermanager.OciSyncAuth, string(configsync.AuthNone)),
fmt.Sprintf("the authentication type for access to the OCI package. Must be one of %s, %s, or %s. Defaults to %s",
configsync.AuthGCPServiceAccount, configsync.AuthGCENode, configsync.AuthNone, configsync.AuthNone))
fmt.Sprintf("the authentication type for access to the OCI package. Must be one of %s, %s, %s, or %s. Defaults to %s",
configsync.AuthGCPServiceAccount, configsync.AuthGCPKSA, configsync.AuthGCENode, configsync.AuthNone, configsync.AuthNone))
var flRoot = flag.String("root", util.EnvString("OCI_SYNC_ROOT", util.EnvString("HOME", "")+"/oci"),
"the root directory for oci-sync operations, under which --dest will be created")
var flDest = flag.String("dest", util.EnvString("OCI_SYNC_DEST", ""),
Expand Down Expand Up @@ -86,7 +86,7 @@ func main() {
switch configsync.AuthType(*flAuth) {
case configsync.AuthNone:
auth = authn.Anonymous
case configsync.AuthGCPServiceAccount, configsync.AuthGCENode:
case configsync.AuthGCPServiceAccount, configsync.AuthGCPKSA, configsync.AuthGCENode:
a, err := google.NewEnvAuthenticator()
if err != nil {
utillog.HandleError(log, true, "ERROR: failed to get the authentication with type %q: %v", *flAuth, err)
Expand Down
2 changes: 2 additions & 0 deletions manifests/reposync-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ spec:
enum:
- gcenode
- gcpserviceaccount
- gcpksa
- none
type: string
dir:
Expand Down Expand Up @@ -1325,6 +1326,7 @@ spec:
enum:
- gcenode
- gcpserviceaccount
- gcpksa
- none
type: string
dir:
Expand Down
2 changes: 2 additions & 0 deletions manifests/rootsync-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ spec:
enum:
- gcenode
- gcpserviceaccount
- gcpksa
- none
type: string
dir:
Expand Down Expand Up @@ -1391,6 +1392,7 @@ spec:
enum:
- gcenode
- gcpserviceaccount
- gcpksa
- none
type: string
dir:
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/configsync/v1alpha1/ociconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type Oci struct {
// Must be one of gcenode, gcpserviceaccount, or none.
// The validation of this is case-sensitive. Required.
//
// +kubebuilder:validation:Enum=gcenode;gcpserviceaccount;none
// +kubebuilder:validation:Enum=gcenode;gcpserviceaccount;gcpksa;none
Auth configsync.AuthType `json:"auth"`

// gcpServiceAccountEmail specifies the GCP service account used to annotate
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/configsync/v1beta1/ociconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type Oci struct {
// Must be one of gcenode, gcpserviceaccount, or none.
// The validation of this is case-sensitive. Required.
//
// +kubebuilder:validation:Enum=gcenode;gcpserviceaccount;none
// +kubebuilder:validation:Enum=gcenode;gcpserviceaccount;gcpksa;none
Auth configsync.AuthType `json:"auth"`

// gcpServiceAccountEmail specifies the GCP service account used to annotate
Expand Down
6 changes: 3 additions & 3 deletions pkg/reconcilermanager/controllers/reconciler_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ func (r *reconcilerBase) upsertServiceAccount(
// Update annotation when Workload Identity is enabled on a GKE cluster.
// In case, Workload Identity is not enabled on a cluster and spec.git.auth: gcpserviceaccount,
// the added annotation will be a no-op.
// if auth == configsync.AuthGCPServiceAccount {
// core.SetAnnotation(childSA, GCPSAAnnotationKey, email)
// }
if auth == configsync.AuthGCPServiceAccount {
core.SetAnnotation(childSA, GCPSAAnnotationKey, email)
}
return nil
})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconcilermanager/controllers/reposync_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ func (r *RepoSyncReconciler) mutationsFor(ctx context.Context, rs *v1beta1.RepoS

func enableAskpassSidecar(sourceType string, auth configsync.AuthType) bool {
if v1beta1.SourceType(sourceType) == v1beta1.GitSource &&
(auth == configsync.AuthGCPServiceAccount || auth == configsync.AuthGCENode) {
(auth == configsync.AuthGCPServiceAccount || auth == configsync.AuthGCPKSA || auth == configsync.AuthGCENode) {
return true
}
return false
Expand Down
4 changes: 2 additions & 2 deletions pkg/reconcilermanager/controllers/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ func getSecret(ctx context.Context, c client.Client, sRef types.NamespacedName,
return c.Get(ctx, sRef, secret)
}

// SkipForAuth returns true if the passed auth is either 'none' or 'gcenode' or
// SkipForAuth returns true if the passed auth is either 'none' or 'gcenode', 'gcpksa' or
// 'gcpserviceaccount'.
func SkipForAuth(auth configsync.AuthType) bool {
switch auth {
case configsync.AuthNone, configsync.AuthGCENode, configsync.AuthGCPServiceAccount:
case configsync.AuthNone, configsync.AuthGCENode, configsync.AuthGCPServiceAccount, configsync.AuthGCPKSA:
return true
default:
return false
Expand Down
4 changes: 2 additions & 2 deletions pkg/reconcilermanager/controllers/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,10 @@ func PollingPeriod(envName string, defaultValue time.Duration) time.Duration {

// useFWIAuth returns whether ConfigSync uses fleet workload identity for authentication.
// It is true only when all the following conditions are true:
// 1. the auth type is `gcpserviceaccount`.
// 1. the auth type is `gcpserviceaccount` or `gcpksa`.
// 2. the cluster is registered in a fleet (the membership object exists).
// 3. the fleet workload identity is enabled (workload_identity_pool and identity_provider are not empty).
func useFWIAuth(authType configsync.AuthType, membership *hubv1.Membership) bool {
return authType == configsync.AuthGCPServiceAccount && membership != nil &&
return (authType == configsync.AuthGCPServiceAccount || authType == configsync.AuthGCPKSA) && membership != nil &&
membership.Spec.IdentityProvider != "" && membership.Spec.WorkloadIdentityPool != ""
}
18 changes: 9 additions & 9 deletions pkg/validate/raw/validate/source_spec_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ func OciSpec(oci *v1beta1.Oci, rs client.Object) status.Error {
// Note that Auth is a case-sensitive field, so ones with arbitrary capitalization
// will fail to apply.
switch oci.Auth {
case configsync.AuthGCENode, configsync.AuthNone:
case configsync.AuthGCENode, configsync.AuthGCPKSA, configsync.AuthNone:
case configsync.AuthGCPServiceAccount:
// if oci.GCPServiceAccountEmail == "" {
// return MissingGCPSAEmail(rs)
// }
// if !validGCPServiceAccountEmail(oci.GCPServiceAccountEmail) {
// return InvalidGCPSAEmail(rs)
// }
if oci.GCPServiceAccountEmail == "" {
return MissingGCPSAEmail(rs)
}
if !validGCPServiceAccountEmail(oci.GCPServiceAccountEmail) {
return InvalidGCPSAEmail(rs)
}
default:
return InvalidOciAuthType(rs)
}
Expand Down Expand Up @@ -254,7 +254,7 @@ func MissingGitRepo(o client.Object) status.Error {
// InvalidAuthType reports that a RootSync/RepoSync doesn't use one of the known auth
// methods.
func InvalidAuthType(o client.Object) status.Error {
types := []string{string(configsync.AuthSSH), string(configsync.AuthCookieFile), string(configsync.AuthGCENode), string(configsync.AuthToken), string(configsync.AuthNone), string(configsync.AuthGCPServiceAccount)}
types := []string{string(configsync.AuthSSH), string(configsync.AuthCookieFile), string(configsync.AuthGCENode), string(configsync.AuthToken), string(configsync.AuthNone), string(configsync.AuthGCPServiceAccount), string(configsync.AuthGCPKSA)}
kind := o.GetObjectKind().GroupVersionKind().Kind
return invalidSyncBuilder.
Sprintf("%ss must specify spec.git.auth to be one of %s", kind,
Expand Down Expand Up @@ -360,7 +360,7 @@ func MissingOciImage(o client.Object) status.Error {
// InvalidOciAuthType reports that a RootSync/RepoSync doesn't use one of the known auth
// methods for OCI image.
func InvalidOciAuthType(o client.Object) status.Error {
types := []string{string(configsync.AuthGCENode), string(configsync.AuthGCPServiceAccount), string(configsync.AuthNone)}
types := []string{string(configsync.AuthGCENode), string(configsync.AuthGCPServiceAccount), string(configsync.AuthGCPKSA), string(configsync.AuthNone)}
kind := o.GetObjectKind().GroupVersionKind().Kind
return invalidSyncBuilder.
Sprintf("%ss must specify spec.oci.auth to be one of %s", kind,
Expand Down

0 comments on commit 87cc242

Please sign in to comment.