Skip to content

Commit 613878b

Browse files
authored
[improvement] use UUID for ephemeral access key instead of os hostname (#210)
<!-- If this is your first PR, welcome! Please make sure you read the [contributing guidelines](../CONTRIBUTING.md). --> <!-- Ensure your PR title complies with the following guidelines 1. All PRs titles should start with one of the following prefixes - `[fix]` for PRs related to bug fixes and patches - `[feat]` for PRs related to new features - `[improvement]` for PRs related to improvements of existing features - `[test]` for PRs related to tests - `[CI]` for PRs related to repo CI improvements - `[docs]` for PRs related to documentation updates - `[deps]` for PRs related to dependency updates 2. if a PR introduces a breaking change it should include `[breaking]` in the title 3. if a PR introduces a deprecation it should include `[deprecation]` in the title --> **What this PR does / why we need it**: **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes # **Special notes for your reviewer**: **TODOs**: <!-- Put an "X" character inside the brackets of each completed task. Some may be optional depending on the PR. --> - [ ] squashed commits - [ ] includes documentation - [ ] adds unit tests - [ ] adds or updates e2e tests
1 parent 22e3718 commit 613878b

File tree

6 files changed

+20
-14
lines changed

6 files changed

+20
-14
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ Follow these steps to get started with Linode COSI Driver:
3131

3232
2. Install Linode COSI Driver using Helm.
3333
```sh
34-
helm install linode-cosi-driver \
35-
./helm/linode-cosi-driver/ \
34+
helm repo add linode-cosi-driver https://linode.github.io/linode-cosi-driver
35+
helm repo update
36+
helm install cosi linode-cosi-driver/linode-cosi-driver \
3637
--set=apiToken=<YOUR_LINODE_API_TOKEN> \
3738
--namespace=linode-cosi-driver \
3839
--create-namespace

Tiltfile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
load('ext://namespace', 'namespace_inject')
12
k8s_yaml(kustomize("./hack/container-object-storage-controller"))
23
k8s_resource(
34
workload="container-object-storage-controller",
@@ -14,11 +15,13 @@ k8s_resource(
1415
"container-object-storage-controller:rolebinding",
1516
"container-object-storage-controller:clusterrolebinding",
1617
])
17-
k8s_yaml(helm( "./helm/linode-cosi-driver",
18+
k8s_yaml(namespace_inject(
19+
helm( "./helm/linode-cosi-driver",
1820
"linode-cosi-driver",
19-
set=[
20-
"apiToken=" + os.getenv("LINODE_TOKEN"),
21-
],
21+
namespace="linode-cosi-driver",
22+
set=["apiToken=" + os.getenv("LINODE_TOKEN")],
23+
),
24+
"linode-cosi-driver"
2225
))
2326

2427
k8s_resource(

cmd/linode-cosi-driver/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func run(ctx context.Context, log *slog.Logger, opts mainOptions) error {
141141
}()
142142

143143
if opts.s3EphemeralCredentials {
144-
creds, cleanup, err := linodeclient.NewEphemeralS3Credentials(ctx, client)
144+
creds, cleanup, err := linodeclient.NewEphemeralS3Credentials(ctx, log, client)
145145
if err != nil {
146146
return fmt.Errorf("unable to create ephemeral credentials: %w", err)
147147
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010
go.uber.org/automaxprocs v1.6.0
1111
google.golang.org/grpc v1.75.1
1212
sigs.k8s.io/container-object-storage-interface-spec v0.1.0
13+
github.com/google/uuid v1.6.0
1314
)
1415

1516
require (

pkg/linodeclient/linodeclient.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ package linodeclient
1717
import (
1818
"context"
1919
"fmt"
20-
"os"
20+
"log/slog"
21+
22+
"github.com/google/uuid"
2123

2224
"github.com/linode/linodego"
2325
)
@@ -60,12 +62,11 @@ func NewLinodeClient(token, ua, apiURL, apiVersion string) (*linodego.Client, er
6062

6163
func NewEphemeralS3Credentials(
6264
ctx context.Context,
65+
slog *slog.Logger,
6366
c *linodego.Client,
6467
) (*linodego.ObjectStorageKey, func(context.Context) error, error) {
65-
hostname, err := os.Hostname()
66-
if err != nil {
67-
return nil, nil, fmt.Errorf("failed to obtain hostname: %w", err)
68-
}
68+
keyLabel := fmt.Sprintf("cosi-%s", uuid.New().String())
69+
slog.Info(fmt.Sprintf("Generating new ephemeral key: %s", keyLabel))
6970

7071
clusters, err := c.ListObjectStorageClusters(ctx, &linodego.ListOptions{})
7172
if err != nil {
@@ -78,7 +79,7 @@ func NewEphemeralS3Credentials(
7879
}
7980

8081
creds, err := c.CreateObjectStorageKey(ctx, linodego.ObjectStorageKeyCreateOptions{
81-
Label: "linode-cosi-" + hostname,
82+
Label: keyLabel,
8283
Regions: regions,
8384
})
8485
if err != nil {

pkg/servers/provisioner/provisionerintegration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func TestHappyPath(t *testing.T) {
7171
return
7272
}
7373

74-
creds, cleanup, err := linodeclient.NewEphemeralS3Credentials(context.Background(), client)
74+
creds, cleanup, err := linodeclient.NewEphemeralS3Credentials(context.Background(), slog.Default(), client)
7575
if err != nil {
7676
t.Errorf("failed to create ephemeral s3 credentials: %v", err.Error())
7777
return

0 commit comments

Comments
 (0)