Skip to content

Commit c4144c4

Browse files
authored
Merge pull request #13 from Keyfactor/ab#65774
v1.1.0
2 parents b69be41 + 8bee15f commit c4144c4

File tree

10 files changed

+548
-55
lines changed

10 files changed

+548
-55
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# v1.1.0
2+
3+
## Features
4+
- Support for sourcing client config files from Azure Key Vault
5+
16
# v1.0.0
27

38
## Features

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,58 @@ servers:
151151
client_id: client-id
152152
client_secret: client-secret
153153
api_path: KeyfactorAPI
154+
```
155+
156+
## Configuration File Providers
157+
158+
Below are a list of configuration file providers that can be used to load configuration from a file if loading from disk
159+
is not desired.
160+
161+
### Azure Key Vault
162+
163+
To use Azure Key Vault as a configuration file provider, the code must either be running in an Azure environment or the
164+
environment configured with `az login`. The following environment variables can be used and will take precedence over
165+
any configuration file. *NOTE* that the secret must be formatted as specified in the example configuration files above.
166+
167+
| Name | Description | Default |
168+
|---------------------|---------------------------------------|---------|
169+
| AZURE_KEYVAULT_NAME | The name of the Azure KeyVault | |
170+
| AZURE_SECRET_NAME | The name of the Azure KeyVault secret | |
171+
172+
#### JSON
173+
174+
Below is an example of a configuration file that uses Azure Key Vault as a configuration file provider. *NOTE* that the
175+
secret must be formatted as specified in the example configuration files above.
176+
177+
```json
178+
{
179+
"servers": {
180+
"default": {
181+
"auth_provider": {
182+
"type": "azid",
183+
"profile": "default",
184+
"parameters": {
185+
"secret_name": "<akv_secret_name>",
186+
"vault_name": "<akv_vault_name>"
187+
}
188+
}
189+
}
190+
}
191+
}
192+
```
193+
194+
#### YAML
195+
196+
Below is an example of a configuration file that uses Azure Key Vault as a configuration file provider. *NOTE* that the
197+
secret must be formatted as specified in the example configuration files above.
198+
199+
```yaml
200+
servers:
201+
default:
202+
auth_provider:
203+
type: azid
204+
profile: default
205+
parameters:
206+
secret_name: <akv_secret_name>
207+
vault_name: <akv_vault_name>
154208
```

auth_providers/auth_basic.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ type CommandAuthConfigBasic struct {
5252
CommandAuthConfig
5353

5454
// Username is the username to be used for authentication to Keyfactor Command API
55-
Username string `json:"username,omitempty"`
55+
Username string `json:"username,omitempty" yaml:"username,omitempty"`
5656

5757
// Password is the password to be used for authentication to Keyfactor Command API
58-
Password string `json:"password,omitempty"`
58+
Password string `json:"password,omitempty" yaml:"password,omitempty"`
5959

6060
// Domain is the domain of the Active Directory used to authenticate to Keyfactor Command API
61-
Domain string `json:"domain,omitempty"`
61+
Domain string `json:"domain,omitempty" yaml:"domain,omitempty"`
6262
}
6363

6464
// NewBasicAuthAuthenticatorBuilder creates a new instance of CommandAuthConfigBasic
@@ -194,8 +194,8 @@ func (a *CommandAuthConfigBasic) Authenticate() error {
194194
return cErr
195195
}
196196

197-
// create oauth Client
198-
authy, err := NewBasicAuthAuthenticatorBuilder().
197+
// create Basic Client
198+
authy, err := a.
199199
WithUsername(a.Username).
200200
WithPassword(a.Password).
201201
WithDomain(a.Domain).

auth_providers/auth_core.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func (f roundTripperFunc) RoundTrip(req *http.Request) (*http.Response, error) {
9898
// CommandAuthConfig represents the base configuration needed for authentication to Keyfactor Command API.
9999
type CommandAuthConfig struct {
100100
// ConfigType is the type of configuration
101-
ConfigType string `json:"config_type"`
101+
ConfigType string `json:"config_type,omitempty" yaml:"config_type,omitempty"`
102102

103103
//ConfigProfile is the profile of the configuration
104104
ConfigProfile string
@@ -110,34 +110,34 @@ type CommandAuthConfig struct {
110110
FileConfig *Server
111111

112112
// AuthHeader is the header to be used for authentication to Keyfactor Command API
113-
AuthHeader string `json:"auth_header"`
113+
AuthHeader string `json:"auth_header,omitempty" yaml:"auth_header,omitempty"`
114114

115115
// CommandHostName is the hostname of the Keyfactor Command API
116-
CommandHostName string `json:"host"`
116+
CommandHostName string `json:"host,omitempty" yaml:"host,omitempty"`
117117

118118
// CommandPort is the port of the Keyfactor Command API
119-
CommandPort int `json:"port"`
119+
CommandPort int `json:"port,omitempty" yaml:"port,omitempty"`
120120

121121
// CommandAPIPath is the path of the Keyfactor Command API, default is "KeyfactorAPI"
122-
CommandAPIPath string `json:"api_path"`
122+
CommandAPIPath string `json:"api_path,omitempty" yaml:"api_path,omitempty"`
123123

124124
// CommandAPIVersion is the version of the Keyfactor Command API, default is "1"
125-
CommandVersion string `json:"command_version"`
125+
CommandVersion string `json:"command_version,omitempty" yaml:"command_version,omitempty"`
126126

127127
// CommandCACert is the CA certificate to be used for authentication to Keyfactor Command API for use with not widely trusted certificates. This can be a filepath or a string of the certificate in PEM format.
128-
CommandCACert string `json:"command_ca_cert"`
128+
CommandCACert string `json:"command_ca_cert,omitempty" yaml:"command_ca_cert,omitempty"`
129129

130130
// SkipVerify is a flag to skip verification of the server's certificate chain and host name. Default is false.
131-
SkipVerify bool `json:"skip_verify"`
131+
SkipVerify bool `json:"skip_verify,omitempty" yaml:"skip_verify,omitempty"`
132132

133133
// HttpClientTimeout is the timeout for the http Client
134-
HttpClientTimeout int `json:"client_timeout"`
134+
HttpClientTimeout int `json:"client_timeout,omitempty" yaml:"client_timeout,omitempty"`
135135

136136
// UserAgent is the user agent to be used for authentication to Keyfactor Command API
137-
UserAgent string `json:"user_agent,omitempty"`
137+
UserAgent string `json:"user_agent,omitempty" yaml:"user_agent,omitempty"`
138138

139139
// Debug
140-
Debug bool `json:"debug,omitempty"`
140+
Debug bool `json:"debug,omitempty" yaml:"debug,omitempty"`
141141

142142
// HttpClient is the http Client to be used for authentication to Keyfactor Command API
143143
HttpClient *http.Client
@@ -731,6 +731,8 @@ func (c *CommandAuthConfig) GetServerConfig() *Server {
731731
return &server
732732
}
733733

734+
type contextKey string
735+
734736
// Example usage of CommandAuthConfig
735737
//
736738
// This example demonstrates how to use CommandAuthConfig to authenticate to the Keyfactor Command API.

auth_providers/auth_oauth.go

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2024 Keyfactor
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package auth_providers
216

317
import (
@@ -72,40 +86,34 @@ type CommandConfigOauth struct {
7286
CommandAuthConfig
7387

7488
// ClientID is the Client ID for OAuth authentication
75-
ClientID string `json:"client_id,omitempty"`
89+
ClientID string `json:"client_id,omitempty" yaml:"client_id,omitempty"`
7690

7791
// ClientSecret is the Client secret for OAuth authentication
78-
ClientSecret string `json:"client_secret,omitempty"`
92+
ClientSecret string `json:"client_secret,omitempty" yaml:"client_secret,omitempty"`
7993

8094
// Audience is the audience for OAuth authentication
81-
Audience string `json:"audience,omitempty"`
95+
Audience string `json:"audience,omitempty" yaml:"audience,omitempty"`
8296

8397
// Scopes is the scopes for OAuth authentication
84-
Scopes []string `json:"scopes,omitempty"`
98+
Scopes []string `json:"scopes,omitempty" yaml:"scopes,omitempty"`
8599

86100
// CACertificatePath is the path to the CA certificate for OAuth authentication
87-
CACertificatePath string `json:"idp_ca_cert,omitempty"`
101+
CACertificatePath string `json:"idp_ca_cert,omitempty" yaml:"idp_ca_cert,omitempty"`
88102

89103
// CACertificates is the CA certificates for authentication
90104
CACertificates []*x509.Certificate `json:"-"`
91105

92106
// AccessToken is the access token for OAuth authentication
93-
AccessToken string `json:"access_token,omitempty"`
107+
AccessToken string `json:"access_token,omitempty" yaml:"access_token,omitempty"`
94108

95109
// RefreshToken is the refresh token for OAuth authentication
96-
RefreshToken string `json:"refresh_token,omitempty"`
110+
RefreshToken string `json:"refresh_token,omitempty" yaml:"refresh_token,omitempty"`
97111

98112
// Expiry is the expiry time of the access token
99-
Expiry time.Time `json:"expiry,omitempty"`
113+
Expiry time.Time `json:"expiry,omitempty" yaml:"expiry,omitempty"`
100114

101115
// TokenURL is the token URL for OAuth authentication
102-
TokenURL string `json:"token_url,omitempty"`
103-
104-
//// AuthPort
105-
//AuthPort string `json:"auth_port,omitempty"`
106-
107-
//// AuthType is the type of OAuth auth to use such as client_credentials, password, etc.
108-
//AuthType string `json:"auth_type,omitempty"`
116+
TokenURL string `json:"token_url,omitempty" yaml:"token_url,omitempty"`
109117
}
110118

111119
// NewOAuthAuthenticatorBuilder creates a new CommandConfigOauth instance.
@@ -372,7 +380,7 @@ func (b *CommandConfigOauth) ValidateAuthConfig() error {
372380
}
373381
}
374382

375-
if b.Scopes == nil || len(b.Scopes) == 0 {
383+
if len(b.Scopes) == 0 {
376384
if scopes, ok := os.LookupEnv(EnvKeyfactorAuthScopes); ok {
377385
// split the scopes by comma
378386
b.Scopes = strings.Split(scopes, ",")
@@ -424,6 +432,7 @@ func (b *CommandConfigOauth) GetServerConfig() *Server {
424432
Port: b.CommandPort,
425433
ClientID: b.ClientID,
426434
ClientSecret: b.ClientSecret,
435+
AccessToken: b.AccessToken,
427436
OAuthTokenUrl: b.TokenURL,
428437
APIPath: b.CommandAPIPath,
429438
Scopes: b.Scopes,

0 commit comments

Comments
 (0)