Skip to content

Commit 413467d

Browse files
Merge branch 'main' into oas-bot-19498933148/pim
2 parents c665c06 + 902a477 commit 413467d

File tree

1,532 files changed

+54837
-3003
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,532 files changed

+54837
-3003
lines changed

.github/dependabot.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

.github/renovate.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"repositories": [
1414
"stackitcloud/stackit-sdk-go"
1515
],
16+
"minimumReleaseAge": "7d",
1617
"enabledManagers": [
1718
"gomod",
1819
"github-actions"
@@ -22,7 +23,8 @@
2223
"matchSourceUrls": [
2324
"https://github.com/stackitcloud/stackit-sdk-go"
2425
],
25-
"groupName": "SDK"
26+
"groupName": "SDK",
27+
"minimumReleaseAge": "0d"
2628
}
2729
],
2830
"allowedCommands": [

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
strategy:
99
matrix:
1010
os: [ubuntu-latest, macos-latest]
11-
go-version: ["1.21", "1.22", "1.23"]
11+
go-version: ["1.21", "1.22", "1.23", "1.24", "1.25"]
1212
runs-on: ${{ matrix.os }}
1313
steps:
1414
- name: Checkout

.github/workflows/stale.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ on:
1111
env:
1212
DAYS_BEFORE_PR_STALE: 7
1313
DAYS_BEFORE_PR_CLOSE: 7
14+
EXEMPT_PR_LABELS: "ignore-stale"
1415

1516
permissions:
1617
issues: write
@@ -30,6 +31,7 @@ jobs:
3031
close-pr-message: "This PR was closed automatically because it has been stalled for ${{ env.DAYS_BEFORE_PR_CLOSE }} days with no activity. Feel free to re-open it at any time."
3132
days-before-pr-stale: ${{ env.DAYS_BEFORE_PR_STALE }}
3233
days-before-pr-close: ${{ env.DAYS_BEFORE_PR_CLOSE }}
34+
exempt-pr-labels: ${{ env.EXEMPT_PR_LABELS }}
3335
# never mark issues as stale or close them
3436
days-before-issue-stale: -1
3537
days-before-issue-close: -1

CHANGELOG.md

Lines changed: 396 additions & 65 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,12 @@ sync-tidy: ## Sync and tidy dependencies
4444
@echo ">> Syncing and tidying dependencies"
4545
@$(SCRIPTS_BASE)/sync-tidy.sh
4646

47-
lint: sync-tidy ## Lint all code
47+
lint: sync-tidy lint-versions ## Lint all code
4848
@$(MAKE) --no-print-directory lint-golangci-lint skip-non-generated-files=${skip-non-generated-files} service=${service}
4949

50+
lint-versions:
51+
@go run $(SCRIPTS_BASE)/lint-versions.go
52+
5053
# TEST
5154
test-go: ## Run Go tests
5255
@echo ">> Running Go tests"
@@ -59,10 +62,3 @@ test-scripts: ## Run tests for scripts
5962
test: ## Run all tests
6063
@$(MAKE) --no-print-directory test-go skip-non-generated-files=${skip-non-generated-files} service=${service}
6164

62-
# AUTOMATIC TAG
63-
sdk-tag-services:
64-
@go run $(SCRIPTS_BASE)/automatic_tag.go --update-type ${update-type} --ssh-private-key-file-path ${ssh-private-key-file-path};
65-
66-
67-
sdk-tag-core:
68-
@go run $(SCRIPTS_BASE)/automatic_tag.go --update-type ${update-type} --ssh-private-key-file-path ${ssh-private-key-file-path} --target core;

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ More examples on other services, configuration and authentication possibilities
9999

100100
## Authentication
101101

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`, see [here](https://docs.stackit.cloud/stackit/en/assign-permissions-to-a-service-account-134415855.html)). You can create a service account through the STACKIT Portal.
102+
To authenticate with the SDK, you need a [service account](https://docs.stackit.cloud/platform/access-and-identity/service-accounts/) with appropriate permissions (e.g., `project.owner`, see [here](https://docs.stackit.cloud/platform/access-and-identity/roles-permissions/assign-roles-to-account/)). You can create a service account through the STACKIT Portal.
103103

104104
### Authentication Methods
105105

@@ -130,8 +130,8 @@ For each authentication method, the key flow is attempted first, followed by the
130130
1. Create a service account key in the STACKIT Portal:
131131

132132
- Navigate to `Service Accounts` → Select account → `Service Account Keys` → Create key
133-
- 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)
133+
- 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/platform/access-and-identity/service-accounts/how-tos/manage-service-account-keys/) 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/platform/access-and-identity/service-accounts/how-tos/manage-service-accounts/) for more details)
135135

136136
2. Save the service account key JSON:
137137

@@ -194,7 +194,7 @@ For each authentication method, the key flow is attempted first, followed by the
194194
1. Create an access token in the STACKIT Portal:
195195

196196
- Navigate to `Service Accounts` → Select account → `Access Tokens` → Create token
197-
- **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)
197+
- **Note**: it's also possible to create the service account access tokens in other ways (see [Tutorials for Service Accounts](https://docs.stackit.cloud/platform/access-and-identity/service-accounts/how-tos/get-access-token/) for more details)
198198

199199
2. Configure authentication using any of these methods:
200200

@@ -234,4 +234,4 @@ See the [release documentation](./RELEASE.md) for further information.
234234

235235
## License
236236

237-
Apache 2.0
237+
Apache 2.0

core/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## v0.21.0
2+
- **Deprecation:** KeyFlow `SetToken` and `GetToken` will be removed after 2026-07-01. Use GetAccessToken instead and rely on client refresh.
3+
- **Feature:** Support Workload Identity Federation flow
4+
5+
## v0.20.1
6+
- **Improvement:** Improve error message when passing a PEM encoded file to as service account key
7+
18
## v0.20.0
29
- **New:** Added new `GetTraceId` function
310

core/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.20.0
1+
v0.21.0

core/auth/auth.go

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/http"
77
"os"
88
"path/filepath"
9+
"strings"
910

1011
"github.com/stackitcloud/stackit-sdk-go/core/clients"
1112
"github.com/stackitcloud/stackit-sdk-go/core/config"
@@ -50,6 +51,12 @@ func SetupAuth(cfg *config.Configuration) (rt http.RoundTripper, err error) {
5051
return nil, fmt.Errorf("configuring no auth client: %w", err)
5152
}
5253
return noAuthRoundTripper, nil
54+
} else if cfg.WorkloadIdentityFederation {
55+
wifRoundTripper, err := WorkloadIdentityFederationAuth(cfg)
56+
if err != nil {
57+
return nil, fmt.Errorf("configuring no auth client: %w", err)
58+
}
59+
return wifRoundTripper, nil
5360
} else if cfg.ServiceAccountKey != "" || cfg.ServiceAccountKeyPath != "" {
5461
keyRoundTripper, err := KeyAuth(cfg)
5562
if err != nil {
@@ -83,14 +90,18 @@ func DefaultAuth(cfg *config.Configuration) (rt http.RoundTripper, err error) {
8390
cfg = &config.Configuration{}
8491
}
8592

86-
// Key flow
87-
rt, err = KeyAuth(cfg)
93+
// WIF flow
94+
rt, err = WorkloadIdentityFederationAuth(cfg)
8895
if err != nil {
89-
keyFlowErr := err
90-
// Token flow
91-
rt, err = TokenAuth(cfg)
96+
// Key flow
97+
rt, err = KeyAuth(cfg)
9298
if err != nil {
93-
return nil, fmt.Errorf("no valid credentials were found: trying key flow: %s, trying token flow: %w", keyFlowErr.Error(), err)
99+
keyFlowErr := err
100+
// Token flow
101+
rt, err = TokenAuth(cfg)
102+
if err != nil {
103+
return nil, fmt.Errorf("no valid credentials were found: trying key flow: %s, trying token flow: %w", keyFlowErr.Error(), err)
104+
}
94105
}
95106
}
96107
return rt, nil
@@ -172,7 +183,11 @@ func KeyAuth(cfg *config.Configuration) (http.RoundTripper, error) {
172183
var serviceAccountKey = &clients.ServiceAccountKeyResponse{}
173184
err = json.Unmarshal([]byte(cfg.ServiceAccountKey), serviceAccountKey)
174185
if err != nil {
175-
return nil, fmt.Errorf("unmarshalling service account key: %w", err)
186+
var errorSuffix string
187+
if strings.HasPrefix(cfg.ServiceAccountKey, "-----BEGIN") {
188+
errorSuffix = " - it seems like the provided service account key is in PEM format. Please provide it in JSON format."
189+
}
190+
return nil, fmt.Errorf("unmarshalling service account key: %w%s", err, errorSuffix)
176191
}
177192

178193
// Try to get private key from configuration, environment or credentials file
@@ -216,6 +231,29 @@ func KeyAuth(cfg *config.Configuration) (http.RoundTripper, error) {
216231
return client, nil
217232
}
218233

234+
// WorkloadIdentityFederationAuth configures the wif flow and returns an http.RoundTripper
235+
// that can be used to make authenticated requests using an access token
236+
func WorkloadIdentityFederationAuth(cfg *config.Configuration) (http.RoundTripper, error) {
237+
wifConfig := clients.WorkloadIdentityFederationFlowConfig{
238+
TokenUrl: cfg.TokenCustomUrl,
239+
BackgroundTokenRefreshContext: cfg.BackgroundTokenRefreshContext,
240+
ClientID: cfg.ServiceAccountEmail,
241+
TokenExpiration: cfg.ServiceAccountFederatedTokenExpiration,
242+
FederatedTokenFunction: cfg.ServiceAccountFederatedTokenFunc,
243+
}
244+
245+
if cfg.HTTPClient != nil && cfg.HTTPClient.Transport != nil {
246+
wifConfig.HTTPTransport = cfg.HTTPClient.Transport
247+
}
248+
249+
client := &clients.WorkloadIdentityFederationFlow{}
250+
if err := client.Init(&wifConfig); err != nil {
251+
return nil, fmt.Errorf("error initializing client: %w", err)
252+
}
253+
254+
return client, nil
255+
}
256+
219257
// readCredentialsFile reads the credentials file from the specified path and returns Credentials
220258
func readCredentialsFile(path string) (*Credentials, error) {
221259
if path == "" {

0 commit comments

Comments
 (0)