Skip to content

Commit 95a5ae4

Browse files
committed
allo to pass auth via env vars
Signed-off-by: Sylvain Hellegouarch <sh@defuze.org>
1 parent 9cc3015 commit 95a5ae4

5 files changed

Lines changed: 48 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22

33
## [Unreleased][]
44

5-
[Unreleased]: https://github.com/chaostoolkit-incubator/chaostoolkit-azure/compare/0.13.0...HEAD
5+
[Unreleased]: https://github.com/chaostoolkit-incubator/chaostoolkit-azure/compare/0.14.0...HEAD
6+
7+
## [0.14.0][] - 2023-07-11
8+
9+
[0.14.0]: https://github.com/chaostoolkit-incubator/chaostoolkit-azure/compare/0.13.0...0.14.0
10+
11+
### Added
12+
13+
* Can now read authentication from environment variables
614

715
## [0.13.0][] - 2023-07-11
816

README.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,22 @@ The extension will first try to load the configuration from the `experiment file
6767

6868
### Credentials
6969

70-
- Secrets in the Experiment file
70+
#### Environment Variables
71+
72+
You can pass credentials via the following environment variables:
73+
74+
- AZURE_CLIENT_ID
75+
- AZURE_CLIENT_SECRET
76+
- AZURE_TENANT_ID
77+
78+
Or:
79+
80+
- AZURE_CLIENT_ID
81+
- AZURE_ACCESS_TOKEN
82+
83+
#### Experiment Secrets
84+
85+
You may also pass them via the secrets block of the experiment:
7186

7287
```json
7388
{
@@ -91,7 +106,7 @@ The extension will first try to load the configuration from the `experiment file
91106
"client_id": "your-super-secret-client-id",
92107
"client_secret": "your-even-more-super-secret-client-secret",
93108
"tenant_id": "your-tenant-id",
94-
"azure_cloud": "AZURE_CHINA_CLOUD"
109+
"cloud": "AZURE_CHINA_CLOUD"
95110
}
96111
```
97112

@@ -102,11 +117,16 @@ The extension will first try to load the configuration from the `experiment file
102117
- AZURE_PUBLIC_CLOUD
103118
- AZURE_US_GOV_CLOUD
104119

120+
Either of these values can be passed via `AZURE_CLOUD` as well.
121+
122+
105123
[vault_secrets]: https://docs.chaostoolkit.org/reference/api/experiment/#vault-secrets
106124
[env_secrets]: https://docs.chaostoolkit.org/reference/api/experiment/#environment-secrets
107125

108126

109-
- Secrets in the Azure credential file
127+
#### Azure Credential File
128+
129+
You may also pass them via the Azure credential file:
110130

111131
You can retrieve a credentials file with your subscription ID already in place by signing in to Azure using the az login command followed by the az ad sp create-for-rbac command
112132

chaosazure/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"init_website_management_client", "init_resource_graph_client", "init_netapp_management_client",
3131
"init_storage_management_client"
3232
]
33-
__version__ = '0.13.0'
33+
__version__ = '0.14.0'
3434

3535

3636
def discover(discover_system: bool = True) -> Discovery:

chaosazure/auth/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import contextlib
2+
import os
23
from typing import Dict
34

45
from chaoslib.exceptions import InterruptExecution
@@ -105,6 +106,12 @@ def __authentication_type(secrets: dict) -> str:
105106
elif 'access_token' in secrets and secrets['access_token']:
106107
return AAD_TOKEN
107108

109+
elif os.getenv("AZURE_CLIENT_SECRET"):
110+
return SERVICE_PRINCIPAL
111+
112+
elif os.getenv("AZURE_ACCESS_TOKEN"):
113+
return AAD_TOKEN
114+
108115
else:
109116
raise InterruptExecution(
110117
"Authentication to Azure requires a"

chaosazure/auth/authentication.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from abc import ABCMeta, abstractmethod
23
from typing import Dict
34

@@ -18,10 +19,10 @@ class ServicePrincipalAuth(Auth):
1819

1920
def create(self, secrets: Dict) -> ClientSecretCredential:
2021
result = ClientSecretCredential(
21-
client_id=secrets.get('client_id'),
22-
client_secret=secrets.get('client_secret'),
23-
tenant_id=secrets.get('tenant_id'),
24-
cloud_environment=secrets.get('cloud')
22+
client_id=secrets.get('client_id', os.getenv("AZURE_CLIENT_ID")),
23+
client_secret=secrets.get('client_secret', os.getenv("AZURE_CLIENT_SECRET")),
24+
tenant_id=secrets.get('tenant_id', os.getenv("AZURE_TENANT_ID")),
25+
cloud_environment=secrets.get('cloud', os.getenv("AZURE_CLOUD"))
2526
)
2627
return result
2728

@@ -30,8 +31,8 @@ class TokenAuth(Auth):
3031

3132
def create(self, secrets: Dict) -> AADTokenCredentials:
3233
result = AADTokenCredentials(
33-
token={"accessToken": secrets['access_token']},
34-
client_id=secrets.get('client_id'),
35-
cloud_environment=secrets.get('cloud'))
34+
token={"accessToken": secrets.get('access_token', os.getenv("AZURE_ACCESS_TOKEN"))},
35+
client_id=secrets.get('client_id', os.getenv("AZURE_CLIENT_ID")),
36+
cloud_environment=secrets.get('cloud', os.getenv("AZURE_CLOUD")))
3637

3738
return result

0 commit comments

Comments
 (0)