You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+88-52Lines changed: 88 additions & 52 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -99,90 +99,126 @@ More examples on other services, configuration and authentication possibilities
99
99
100
100
## Authentication
101
101
102
-
To authenticate to the SDK, you will need a [service account](https://docs.stackit.cloud/stackit/en/service-accounts-134415819.html). Create it in the STACKIT Portal an assign it the necessary permissions, e.g. `project.owner`. There are multiple ways to authenticate:
102
+
To authenticate with the SDK, you need a [service account](https://docs.stackit.cloud/stackit/en/service-accounts-134415819.html) with appropriate permissions (e.g.,`project.owner`). You can create a service account through the STACKIT Portal.
103
103
104
-
- Key flow (recommended)
105
-
- Token flow
104
+
### Authentication Methods
106
105
107
-
When setting up authentication, the SDK will always try to use the key flow first and search for credentials in several locations, following a specific order:
106
+
The SDK supports two authentication methods:
108
107
109
-
1. Explicit configuration, e.g. by using the option `config.WithServiceAccountKeyPath("path/to/sa_key.json")`
110
-
2. Environment variable, e.g. by setting `STACKIT_SERVICE_ACCOUNT_KEY_PATH`
111
-
3. Credentials file
108
+
1.**Key Flow** (Recommended)
112
109
113
-
The SDK will check the credentials file located in the path defined by the `STACKIT_CREDENTIALS_PATH` env var, if specified,
114
-
or in `$HOME/.stackit/credentials.json` as a fallback.
115
-
The credentials file should be a json and each credential should be set using the name of the respective environment variable, as stated below in each flow. Example:
110
+
- Uses RSA key-pair based authentication
111
+
- Provides better security through short-lived tokens
112
+
- Supports both STACKIT-generated and custom key pairs
When creating the service account key, a new pair can be created automatically, which will be included in the service account key. This will make it much easier to configure the key flow authentication in the CLI, by just providing the service account key.
126
+
For each authentication method, the keyflow is attempted first, followed by the token flow.
133
127
134
-
**Optionally**, you can provide your own private key when creating the service account key, which will then require you to also provide it explicitly to the CLI, additionaly to the service account key. Check the STACKIT Knowledge Base for an [example of how to create your own key-pair](https://docs.stackit.cloud/stackit/en/usage-of-the-service-account-keys-in-stackit-175112464.html#UsageoftheserviceaccountkeysinSTACKIT-CreatinganRSAkey-pair).
128
+
### Using the Key Flow
135
129
136
-
To configure the key flow, follow this steps:
130
+
1. Create a service account key in the STACKIT Portal:
- You can either let STACKIT generate the key pair or provide your own RSA key pair (see [Creating an RSA key-pair](https://docs.stackit.cloud/stackit/en/usage-of-the-service-account-keys-in-stackit-175112464.html#UsageoftheserviceaccountkeysinSTACKIT-CreatinganRSAkey-pair) for more details)
134
+
-**Note**: it's also possible to create the service account key in other ways (see [Tutorials for Service Accounts](https://docs.stackit.cloud/stackit/en/tutorials-for-service-accounts-134415861.html) for more details)
139
135
140
-
- Use the STACKIT Portal: go to the `Service Accounts` tab, choose a `Service Account` and go to `Service Account Keys` to create a key. For more details, see [Create a service account key](https://docs.stackit.cloud/stackit/en/create-a-service-account-key-175112456.html)
141
-
142
-
2. Save the content of the service account key by copying it and saving it in a JSON file.
143
-
144
-
The expected format of the service account key is a **json** with the following structure:
3. Configure the service account key for authentication in the SDK by following one of the alternatives below:
167
-
- using the configuration options: `config.WithServiceAccountKey` or `config.WithServiceAccountKeyPath`, `config.WithPrivateKey` or `config.WithPrivateKeyPath`
168
-
- setting the environment variable: `STACKIT_SERVICE_ACCOUNT_KEY_PATH`
169
-
- setting `STACKIT_SERVICE_ACCOUNT_KEY_PATH` in the credentials file (see above)
153
+
3. Configure authentication using any of these methods:
170
154
171
-
> **Optionally, only if you have provided your own RSA key-pair when creating the service account key**, you also need to configure your private key (takes precedence over the one included in the service account key, if present). **The private key must be PEM encoded** and can be provided using one of the options below:
172
-
>
173
-
> - using the configuration options: `config.WithPrivateKey` or `config.WithPrivateKeyPath`
174
-
> - setting the environment variable: `STACKIT_PRIVATE_KEY_PATH`
175
-
> - setting `STACKIT_PRIVATE_KEY_PATH` in the credentials file (see above)
155
+
**A. Code Configuration**
176
156
177
-
4. The SDK will search for the keys and, if valid, will use them to get access and refresh tokens which will be used to authenticate all the requests.
-**Note**: it's also possible to create the service account access tokens in other ways (see [Tutorials for Service Accounts](https://docs.stackit.cloud/stackit/en/tutorials-for-service-accounts-134415861.html) for more details)
198
+
199
+
2. Configure authentication using any of these methods:
0 commit comments