@@ -13,44 +13,68 @@ import (
1313 "github.com/go-acme/lego/v4/challenge/dns01"
1414)
1515
16+ const (
17+ authMethodEnv = "env"
18+ authMethodWLI = "wli"
19+ authMethodMSI = "msi"
20+ authMethodCLI = "cli"
21+ authMethodOIDC = "oidc"
22+ authMethodPipeline = "pipeline"
23+ )
24+
25+ //nolint:gocyclo // The complexity is related to the number of possible configurations.
1626func getCredentials (config * Config ) (azcore.TokenCredential , error ) {
1727 clientOptions := azcore.ClientOptions {Cloud : config .Environment }
1828
1929 switch strings .ToLower (config .AuthMethod ) {
20- case "env" :
30+ case authMethodEnv :
2131 if config .ClientID != "" && config .ClientSecret != "" && config .TenantID != "" {
2232 return azidentity .NewClientSecretCredential (config .TenantID , config .ClientID , config .ClientSecret ,
2333 & azidentity.ClientSecretCredentialOptions {ClientOptions : clientOptions })
2434 }
2535
2636 return azidentity .NewEnvironmentCredential (& azidentity.EnvironmentCredentialOptions {ClientOptions : clientOptions })
2737
28- case "wli" :
38+ case authMethodWLI :
2939 return azidentity .NewWorkloadIdentityCredential (& azidentity.WorkloadIdentityCredentialOptions {ClientOptions : clientOptions })
3040
31- case "msi" :
41+ case authMethodMSI :
3242 cred , err := azidentity .NewManagedIdentityCredential (& azidentity.ManagedIdentityCredentialOptions {ClientOptions : clientOptions })
3343 if err != nil {
3444 return nil , err
3545 }
3646
3747 return & timeoutTokenCredential {cred : cred , timeout : config .AuthMSITimeout }, nil
3848
39- case "cli" :
49+ case authMethodCLI :
4050 var credOptions * azidentity.AzureCLICredentialOptions
4151 if config .TenantID != "" {
4252 credOptions = & azidentity.AzureCLICredentialOptions {TenantID : config .TenantID }
4353 }
4454 return azidentity .NewAzureCLICredential (credOptions )
4555
46- case "oidc" :
56+ case authMethodOIDC :
4757 err := checkOIDCConfig (config )
4858 if err != nil {
4959 return nil , err
5060 }
5161
5262 return azidentity .NewClientAssertionCredential (config .TenantID , config .ClientID , getOIDCAssertion (config ), & azidentity.ClientAssertionCredentialOptions {ClientOptions : clientOptions })
5363
64+ case authMethodPipeline :
65+ err := checkPipelineConfig (config )
66+ if err != nil {
67+ return nil , err
68+ }
69+
70+ // Uses the env var `SYSTEM_OIDCREQUESTURI`,
71+ // but the constant is not exported,
72+ // and there is no way to set it programmatically.
73+ // https://github.com/Azure/azure-sdk-for-go/blob/aae2fb75ffccafc669db72bebc3c1a66332f48d7/sdk/azidentity/azure_pipelines_credential.go#L22
74+ // https://github.com/Azure/azure-sdk-for-go/blob/aae2fb75ffccafc669db72bebc3c1a66332f48d7/sdk/azidentity/azure_pipelines_credential.go#L79
75+
76+ return azidentity .NewAzurePipelinesCredential (config .TenantID , config .ClientID , config .ServiceConnectionID , config .SystemAccessToken , & azidentity.AzurePipelinesCredentialOptions {ClientOptions : clientOptions })
77+
5478 default :
5579 return azidentity .NewDefaultAzureCredential (& azidentity.DefaultAzureCredentialOptions {ClientOptions : clientOptions })
5680 }
@@ -97,3 +121,15 @@ func getZoneName(config *Config, fqdn string) (string, error) {
97121
98122 return authZone , nil
99123}
124+
125+ func checkPipelineConfig (config * Config ) error {
126+ if config .ServiceConnectionID == "" {
127+ return errors .New ("azuredns: ServiceConnectionID is missing" )
128+ }
129+
130+ if config .SystemAccessToken == "" {
131+ return errors .New ("azuredns: SystemAccessToken is missing" )
132+ }
133+
134+ return nil
135+ }
0 commit comments