Skip to content
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

add upbound credentials source #473

Merged
merged 2 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apis/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type ProviderConfigSpec struct {
// ProviderCredentials required to authenticate.
type ProviderCredentials struct {
// Source of the provider credentials.
// +kubebuilder:validation:Enum=None;Secret;UserAssignedManagedIdentity;SystemAssignedManagedIdentity;OIDCTokenFile
// +kubebuilder:validation:Enum=None;Secret;UserAssignedManagedIdentity;SystemAssignedManagedIdentity;OIDCTokenFile;Upbound
Source xpv1.CredentialsSource `json:"source"`

xpv1.CommonCredentialSelectors `json:",inline"`
Expand Down
10 changes: 10 additions & 0 deletions examples/providerconfig/upbound.yaml
avalanche123 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: azure.upbound.io/v1beta1
kind: ProviderConfig
metadata:
name: default
spec:
clientID: <client ID>
tenantID: <tenant ID>
subscriptionID: <subscription ID>
credentials:
source: Upbound
30 changes: 27 additions & 3 deletions internal/clients/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ const (
errTrackUsage = "cannot track ProviderConfig usage"
errExtractCredentials = "cannot extract credentials"
errUnmarshalCredentials = "cannot unmarshal Azure credentials as JSON"
errSubscriptionIDNotSet = "subscription ID must be set in ProviderConfig when credential source is InjectedIdentity"
errTenantIDNotSet = "tenant ID must be set in ProviderConfig when credential source is InjectedIdentity"
errClientIDNotSet = "Client ID must be set in ProviderConfig when credential source is OIDCTokenFile"
errSubscriptionIDNotSet = "subscription ID must be set in ProviderConfig when credential source is InjectedIdentity, OIDCTokenFile or Upbound"
errTenantIDNotSet = "tenant ID must be set in ProviderConfig when credential source is InjectedIdentity, OIDCTokenFile or Upbound"
errClientIDNotSet = "client ID must be set in ProviderConfig when credential source is OIDCTokenFile or Upbound"
// Azure service principal credentials file JSON keys
keyAzureSubscriptionID = "subscriptionId"
keyAzureClientID = "clientId"
Expand All @@ -51,6 +51,9 @@ var (
credentialsSourceUserAssignedManagedIdentity xpv1.CredentialsSource = "UserAssignedManagedIdentity"
credentialsSourceSystemAssignedManagedIdentity xpv1.CredentialsSource = "SystemAssignedManagedIdentity"
credentialsSourceOIDCTokenFile xpv1.CredentialsSource = "OIDCTokenFile"
credentialsSourceUpbound xpv1.CredentialsSource = "Upbound"

upboundProviderIdentityTokenFile = "/var/run/secrets/upbound.io/provider/token"
)

// TerraformSetupBuilder returns Terraform setup with provider specific
Expand Down Expand Up @@ -98,6 +101,8 @@ func TerraformSetupBuilder(version, providerSource, providerVersion string, sche
err = msiAuth(pc, &ps)
case credentialsSourceOIDCTokenFile:
err = oidcAuth(pc, &ps)
case credentialsSourceUpbound:
err = upboundAuth(pc, &ps)
default:
err = spAuth(ctx, pc, &ps, client)
}
Expand Down Expand Up @@ -179,3 +184,22 @@ func oidcAuth(pc *v1beta1.ProviderConfig, ps *terraform.Setup) error {
return nil

}

func upboundAuth(pc *v1beta1.ProviderConfig, ps *terraform.Setup) error {
if pc.Spec.SubscriptionID == nil || len(*pc.Spec.SubscriptionID) == 0 {
avalanche123 marked this conversation as resolved.
Show resolved Hide resolved
return errors.New(errSubscriptionIDNotSet)
}
if pc.Spec.TenantID == nil || len(*pc.Spec.TenantID) == 0 {
return errors.New(errTenantIDNotSet)
}
if pc.Spec.ClientID == nil || len(*pc.Spec.ClientID) == 0 {
return errors.New(errClientIDNotSet)
}
ps.Configuration[keyOidcTokenFilePath] = upboundProviderIdentityTokenFile
ps.Configuration[keySubscriptionID] = *pc.Spec.SubscriptionID
ps.Configuration[keyTenantID] = *pc.Spec.TenantID
ps.Configuration[keyClientID] = *pc.Spec.ClientID
ps.Configuration[keyUseOIDC] = "true"
return nil

}
1 change: 1 addition & 0 deletions package/crds/azure.upbound.io_providerconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ spec:
- UserAssignedManagedIdentity
- SystemAssignedManagedIdentity
- OIDCTokenFile
- Upbound
type: string
required:
- source
Expand Down