66 "context"
77 "errors"
88 "fmt"
9+ "net/http"
910 "strings"
1011 "time"
1112
@@ -31,12 +32,20 @@ const (
3132 EnvClientID = envNamespace + "CLIENT_ID"
3233 EnvClientSecret = envNamespace + "CLIENT_SECRET"
3334
35+ EnvOIDCToken = envNamespace + "OIDC_TOKEN"
36+ EnvOIDCTokenFilePath = envNamespace + "OIDC_TOKEN_FILE_PATH"
37+ EnvOIDCRequestURL = envNamespace + "OIDC_REQUEST_URL"
38+ EnvOIDCRequestToken = envNamespace + "OIDC_REQUEST_TOKEN"
39+
3440 EnvAuthMethod = envNamespace + "AUTH_METHOD"
3541 EnvAuthMSITimeout = envNamespace + "AUTH_MSI_TIMEOUT"
3642
3743 EnvTTL = envNamespace + "TTL"
3844 EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
3945 EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
46+
47+ EnvGitHubOIDCRequestURL = "ACTIONS_ID_TOKEN_REQUEST_URL"
48+ EnvGitHubOIDCRequestToken = "ACTIONS_ID_TOKEN_REQUEST_TOKEN"
4049)
4150
4251// Config is used to configure the creation of the DNSProvider.
@@ -52,12 +61,18 @@ type Config struct {
5261 ClientSecret string
5362 TenantID string
5463
64+ OIDCToken string
65+ OIDCTokenFilePath string
66+ OIDCRequestURL string
67+ OIDCRequestToken string
68+
5569 AuthMethod string
5670 AuthMSITimeout time.Duration
5771
5872 PropagationTimeout time.Duration
5973 PollingInterval time.Duration
6074 TTL int
75+ HTTPClient * http.Client
6176}
6277
6378// NewDefaultConfig returns a default configuration for the DNSProvider.
@@ -103,6 +118,17 @@ func NewDNSProvider() (*DNSProvider, error) {
103118 config .ClientSecret = env .GetOrFile (EnvClientSecret )
104119 config .TenantID = env .GetOrFile (EnvTenantID )
105120
121+ config .OIDCToken = env .GetOrFile (EnvOIDCToken )
122+ config .OIDCTokenFilePath = env .GetOrFile (EnvOIDCTokenFilePath )
123+
124+ oidcValues , _ := env .GetWithFallback (
125+ []string {EnvOIDCRequestURL , EnvGitHubOIDCRequestURL },
126+ []string {EnvOIDCRequestToken , EnvGitHubOIDCRequestToken },
127+ )
128+
129+ config .OIDCRequestURL = oidcValues [EnvOIDCRequestURL ]
130+ config .OIDCRequestToken = oidcValues [EnvOIDCRequestToken ]
131+
106132 config .AuthMethod = env .GetOrFile (EnvAuthMethod )
107133 config .AuthMSITimeout = env .GetOrDefaultSecond (EnvAuthMSITimeout , 2 * time .Second )
108134
@@ -115,6 +141,10 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
115141 return nil , errors .New ("azuredns: the configuration of the DNS provider is nil" )
116142 }
117143
144+ if config .HTTPClient == nil {
145+ config .HTTPClient = & http.Client {Timeout : 5 * time .Second }
146+ }
147+
118148 credentials , err := getCredentials (config )
119149 if err != nil {
120150 return nil , fmt .Errorf ("azuredns: Unable to retrieve valid credentials: %w" , err )
@@ -144,6 +174,22 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
144174 return & DNSProvider {provider : dnsProvider }, nil
145175}
146176
177+ // Timeout returns the timeout and interval to use when checking for DNS propagation.
178+ // Adjusting here to cope with spikes in propagation times.
179+ func (d * DNSProvider ) Timeout () (timeout , interval time.Duration ) {
180+ return d .provider .Timeout ()
181+ }
182+
183+ // Present creates a TXT record to fulfill the dns-01 challenge.
184+ func (d * DNSProvider ) Present (domain , token , keyAuth string ) error {
185+ return d .provider .Present (domain , token , keyAuth )
186+ }
187+
188+ // CleanUp removes the TXT record matching the specified parameters.
189+ func (d * DNSProvider ) CleanUp (domain , token , keyAuth string ) error {
190+ return d .provider .CleanUp (domain , token , keyAuth )
191+ }
192+
147193func getCredentials (config * Config ) (azcore.TokenCredential , error ) {
148194 clientOptions := azcore.ClientOptions {Cloud : config .Environment }
149195
@@ -170,27 +216,19 @@ func getCredentials(config *Config) (azcore.TokenCredential, error) {
170216 case "cli" :
171217 return azidentity .NewAzureCLICredential (nil )
172218
219+ case "oidc" :
220+ err := checkOIDCConfig (config )
221+ if err != nil {
222+ return nil , err
223+ }
224+
225+ return azidentity .NewClientAssertionCredential (config .TenantID , config .ClientID , getOIDCAssertion (config ), & azidentity.ClientAssertionCredentialOptions {ClientOptions : clientOptions })
226+
173227 default :
174228 return azidentity .NewDefaultAzureCredential (& azidentity.DefaultAzureCredentialOptions {ClientOptions : clientOptions })
175229 }
176230}
177231
178- // Timeout returns the timeout and interval to use when checking for DNS propagation.
179- // Adjusting here to cope with spikes in propagation times.
180- func (d * DNSProvider ) Timeout () (timeout , interval time.Duration ) {
181- return d .provider .Timeout ()
182- }
183-
184- // Present creates a TXT record to fulfill the dns-01 challenge.
185- func (d * DNSProvider ) Present (domain , token , keyAuth string ) error {
186- return d .provider .Present (domain , token , keyAuth )
187- }
188-
189- // CleanUp removes the TXT record matching the specified parameters.
190- func (d * DNSProvider ) CleanUp (domain , token , keyAuth string ) error {
191- return d .provider .CleanUp (domain , token , keyAuth )
192- }
193-
194232// timeoutTokenCredential wraps a TokenCredential to add a timeout.
195233type timeoutTokenCredential struct {
196234 cred azcore.TokenCredential
0 commit comments