-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[library usage] Implement library token provider (#380)
* feat: define types * refactor: move environment variables to `internal/env` * feat: implement OptionsWithEnv * feat: convert library options to internal options * feat: implement library token provider * fix: drop ROPCLogin from library usage for now * doc: typo
- Loading branch information
Showing
10 changed files
with
473 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package env | ||
|
||
const ( | ||
// env vars | ||
LoginMethod = "AAD_LOGIN_METHOD" | ||
KubeloginROPCUsername = "AAD_USER_PRINCIPAL_NAME" | ||
KubeloginROPCPassword = "AAD_USER_PRINCIPAL_PASSWORD" | ||
KubeloginClientID = "AAD_SERVICE_PRINCIPAL_CLIENT_ID" | ||
KubeloginClientSecret = "AAD_SERVICE_PRINCIPAL_CLIENT_SECRET" | ||
KubeloginClientCertificatePath = "AAD_SERVICE_PRINCIPAL_CLIENT_CERTIFICATE" | ||
KubeloginClientCertificatePassword = "AAD_SERVICE_PRINCIPAL_CLIENT_CERTIFICATE_PASSWORD" | ||
|
||
// env vars used by Terraform | ||
TerraformClientID = "ARM_CLIENT_ID" | ||
TerraformClientSecret = "ARM_CLIENT_SECRET" | ||
TerraformClientCertificatePath = "ARM_CLIENT_CERTIFICATE_PATH" | ||
TerraformClientCertificatePassword = "ARM_CLIENT_CERTIFICATE_PASSWORD" | ||
TerraformTenantID = "ARM_TENANT_ID" | ||
|
||
// env vars following azure sdk naming convention | ||
AzureAuthorityHost = "AZURE_AUTHORITY_HOST" | ||
AzureClientCertificatePassword = "AZURE_CLIENT_CERTIFICATE_PASSWORD" | ||
AzureClientCertificatePath = "AZURE_CLIENT_CERTIFICATE_PATH" | ||
AzureClientID = "AZURE_CLIENT_ID" | ||
AzureClientSecret = "AZURE_CLIENT_SECRET" | ||
AzureFederatedTokenFile = "AZURE_FEDERATED_TOKEN_FILE" | ||
AzureTenantID = "AZURE_TENANT_ID" | ||
AzureUsername = "AZURE_USERNAME" | ||
AzurePassword = "AZURE_PASSWORD" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package token | ||
|
||
import "github.com/Azure/kubelogin/pkg/internal/token" | ||
|
||
// list of supported login methods for library consumers | ||
|
||
const ( | ||
ServicePrincipalLogin = token.ServicePrincipalLogin | ||
MSILogin = token.MSILogin | ||
WorkloadIdentityLogin = token.WorkloadIdentityLogin | ||
) | ||
|
||
// Options defines the options for getting token. | ||
// This struct is a subset of internal/token.Options where its values are copied | ||
// to internal type. See internal/token/options.go for details | ||
type Options struct { | ||
LoginMethod string | ||
|
||
// shared login settings | ||
|
||
Environment string | ||
TenantID string | ||
ServerID string | ||
ClientID string | ||
|
||
// for ServicePrincipalLogin | ||
|
||
ClientSecret string | ||
ClientCert string | ||
ClientCertPassword string | ||
IsPoPTokenEnabled bool | ||
PoPTokenClaims string | ||
|
||
// for MSILogin | ||
|
||
IdentityResourceID string | ||
|
||
// for WorkloadIdentityLogin | ||
|
||
AuthorityHost string | ||
FederatedTokenFile string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package token | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/Azure/kubelogin/pkg/internal/env" | ||
"github.com/Azure/kubelogin/pkg/internal/token" | ||
) | ||
|
||
// OptionsWithEnv loads options from environment variables. | ||
func OptionsWithEnv() *Options { | ||
// initial default values | ||
rv := &Options{ | ||
LoginMethod: os.Getenv(env.LoginMethod), | ||
TenantID: os.Getenv(env.AzureTenantID), | ||
ClientID: os.Getenv(env.KubeloginClientID), | ||
ClientSecret: os.Getenv(env.KubeloginClientSecret), | ||
ClientCert: os.Getenv(env.KubeloginClientCertificatePath), | ||
ClientCertPassword: os.Getenv(env.KubeloginClientCertificatePassword), | ||
AuthorityHost: os.Getenv(env.AzureAuthorityHost), | ||
FederatedTokenFile: os.Getenv(env.AzureFederatedTokenFile), | ||
} | ||
|
||
// azure variant overrides | ||
if v, ok := os.LookupEnv(env.AzureClientID); ok { | ||
rv.ClientID = v | ||
} | ||
if v, ok := os.LookupEnv(env.AzureClientSecret); ok { | ||
rv.ClientSecret = v | ||
} | ||
if v, ok := os.LookupEnv(env.AzureClientCertificatePath); ok { | ||
rv.ClientCert = v | ||
} | ||
if v, ok := os.LookupEnv(env.AzureClientCertificatePassword); ok { | ||
rv.ClientCertPassword = v | ||
} | ||
|
||
return rv | ||
} | ||
|
||
func (opts *Options) toInternalOptions() *token.Options { | ||
return &token.Options{ | ||
LoginMethod: opts.LoginMethod, | ||
Environment: opts.Environment, | ||
TenantID: opts.TenantID, | ||
ServerID: opts.ServerID, | ||
ClientID: opts.ClientID, | ||
ClientSecret: opts.ClientSecret, | ||
ClientCert: opts.ClientCert, | ||
ClientCertPassword: opts.ClientCertPassword, | ||
IsPoPTokenEnabled: opts.IsPoPTokenEnabled, | ||
PoPTokenClaims: opts.PoPTokenClaims, | ||
IdentityResourceID: opts.IdentityResourceID, | ||
AuthorityHost: opts.AuthorityHost, | ||
FederatedTokenFile: opts.FederatedTokenFile, | ||
} | ||
} |
Oops, something went wrong.