Skip to content

Commit 6e58904

Browse files
Migrate from 99designs/keyring to zalando/go-keyring (#119)
1 parent 85c5cbb commit 6e58904

File tree

11 files changed

+255
-137
lines changed

11 files changed

+255
-137
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ ifeq ($(OS),Windows_NT)
33
BINARY_NAME=lstk.exe
44
endif
55
BUILD_DIR=bin
6+
export CGO_ENABLED=0
67

78
.PHONY: build clean test test-integration lint mock-generate
89

go.mod

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module github.com/localstack/lstk
33
go 1.26.1
44

55
require (
6-
github.com/99designs/keyring v1.2.2
76
github.com/charmbracelet/bubbles v1.0.0
87
github.com/charmbracelet/bubbletea v1.3.10
98
github.com/charmbracelet/lipgloss v1.1.0
@@ -17,14 +16,15 @@ require (
1716
github.com/spf13/cobra v1.10.2
1817
github.com/spf13/viper v1.21.0
1918
github.com/stretchr/testify v1.11.1
19+
github.com/zalando/go-keyring v0.2.6
2020
go.uber.org/mock v0.6.0
2121
golang.org/x/term v0.41.0
2222
gopkg.in/ini.v1 v1.67.1
2323
gotest.tools/v3 v3.5.2
2424
)
2525

2626
require (
27-
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
27+
al.essio.dev/pkg/shellescape v1.5.1 // indirect
2828
github.com/Microsoft/go-winio v0.6.2 // indirect
2929
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
3030
github.com/aymanbagabas/go-udiff v0.3.1 // indirect
@@ -43,16 +43,14 @@ require (
4343
github.com/davecgh/go-spew v1.1.1 // indirect
4444
github.com/distribution/reference v0.6.0 // indirect
4545
github.com/docker/go-units v0.5.0 // indirect
46-
github.com/dvsekhvalnov/jose2go v1.8.0 // indirect
4746
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
4847
github.com/felixge/httpsnoop v1.0.4 // indirect
4948
github.com/fsnotify/fsnotify v1.9.0 // indirect
5049
github.com/go-logr/logr v1.4.3 // indirect
5150
github.com/go-logr/stdr v1.2.2 // indirect
5251
github.com/go-viper/mapstructure/v2 v2.5.0 // indirect
53-
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
52+
github.com/godbus/dbus/v5 v5.1.0 // indirect
5453
github.com/google/go-cmp v0.7.0 // indirect
55-
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
5654
github.com/inconshreveable/mousetrap v1.1.0 // indirect
5755
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
5856
github.com/mattn/go-isatty v0.0.20 // indirect
@@ -62,7 +60,6 @@ require (
6260
github.com/moby/sys/atomicwriter v0.1.0 // indirect
6361
github.com/moby/term v0.5.2 // indirect
6462
github.com/morikuni/aec v1.1.0 // indirect
65-
github.com/mtibben/percent v0.2.1 // indirect
6663
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
6764
github.com/muesli/cancelreader v0.2.2 // indirect
6865
github.com/opencontainers/go-digest v1.0.0 // indirect

go.sum

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs=
2-
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4/go.mod h1:hN7oaIRCjzsZ2dE+yG5k+rsdt3qcwykqK6HVGcKwsw4=
3-
github.com/99designs/keyring v1.2.2 h1:pZd3neh/EmUzWONb35LxQfvuY7kiSXAq3HQd97+XBn0=
4-
github.com/99designs/keyring v1.2.2/go.mod h1:wes/FrByc8j7lFOAGLGSNEg8f/PaI3cgTBqhFkHUrPk=
1+
al.essio.dev/pkg/shellescape v1.5.1 h1:86HrALUujYS/h+GtqoB26SBEdkWfmMI6FubjXlsXyho=
2+
al.essio.dev/pkg/shellescape v1.5.1/go.mod h1:6sIqp7X2P6mThCQ7twERpZTuigpr6KbZWtls1U8I890=
53
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c h1:udKWzYgxTojEKWjV8V+WSxDXJ4NFATAsZjh8iIbsQIg=
64
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
75
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
@@ -58,8 +56,6 @@ github.com/docker/go-connections v0.6.0 h1:LlMG9azAe1TqfR7sO+NJttz1gy6KO7VJBh+pM
5856
github.com/docker/go-connections v0.6.0/go.mod h1:AahvXYshr6JgfUJGdDCs2b5EZG/vmaMAntpSFH5BFKE=
5957
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
6058
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
61-
github.com/dvsekhvalnov/jose2go v1.8.0 h1:LqkkVKAlHFfH9LOEl5fe4p/zL02OhWE7pCufMBG2jLA=
62-
github.com/dvsekhvalnov/jose2go v1.8.0/go.mod h1:QsHjhyTlD/lAVqn/NSbVZmSCGeDehTB/mPZadG+mhXU=
6359
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
6460
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
6561
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
@@ -75,22 +71,20 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
7571
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
7672
github.com/go-viper/mapstructure/v2 v2.5.0 h1:vM5IJoUAy3d7zRSVtIwQgBj7BiWtMPfmPEgAXnvj1Ro=
7773
github.com/go-viper/mapstructure/v2 v2.5.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
78-
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 h1:ZpnhV/YsD2/4cESfV5+Hoeu/iUR3ruzNvZ+yQfO03a0=
79-
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4=
74+
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
75+
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
8076
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
8177
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
78+
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
79+
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
8280
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
8381
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
8482
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3 h1:NmZ1PKzSTQbuGHw9DGPFomqkkLWMC+vZCkfs+FHv1Vg=
8583
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3/go.mod h1:zQrxl1YP88HQlA6i9c63DSVPFklWpGX4OWAc9bFuaH4=
86-
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU=
87-
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0=
8884
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
8985
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
9086
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
9187
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
92-
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
93-
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
9488
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
9589
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
9690
github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag=
@@ -111,15 +105,12 @@ github.com/moby/term v0.5.2 h1:6qk3FJAFDs6i/q3W/pQ97SX192qKfZgGjCQqfCJkgzQ=
111105
github.com/moby/term v0.5.2/go.mod h1:d3djjFCrjnB+fl8NJux+EJzu0msscUP+f8it8hPkFLc=
112106
github.com/morikuni/aec v1.1.0 h1:vBBl0pUnvi/Je71dsRrhMBtreIqNMYErSAbEeb8jrXQ=
113107
github.com/morikuni/aec v1.1.0/go.mod h1:xDRgiq/iw5l+zkao76YTKzKttOp2cwPEne25HDkJnBw=
114-
github.com/mtibben/percent v0.2.1 h1:5gssi8Nqo8QU/r2pynCm+hBQHpkB/uNK7BJCFogWdzs=
115-
github.com/mtibben/percent v0.2.1/go.mod h1:KG9uO+SZkUp+VkRHsCdYQV3XSZrrSpR3O9ibNBTZrns=
116108
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
117109
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
118110
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
119111
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
120112
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
121113
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
122-
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
123114
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
124115
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
125116
github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040=
@@ -166,6 +157,8 @@ github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8
166157
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
167158
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
168159
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
160+
github.com/zalando/go-keyring v0.2.6 h1:r7Yc3+H+Ux0+M72zacZoItR3UDxeWfKTcabvkI8ua9s=
161+
github.com/zalando/go-keyring v0.2.6/go.mod h1:2TCrxYrbUNYfNS/Kgy/LSrkSQzZ5UPVH85RwfczwvcI=
169162
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
170163
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
171164
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.65.0 h1:7iP2uCb7sGddAr30RRS6xjKy7AZ2JtTOPA3oolgVSw8=
@@ -214,7 +207,6 @@ google.golang.org/grpc v1.77.0/go.mod h1:z0BY1iVj0q8E1uSQCjL9cppRj+gnZjzDnzV0dHh
214207
google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE=
215208
google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
216209
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
217-
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
218210
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
219211
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
220212
gopkg.in/ini.v1 v1.67.1 h1:tVBILHy0R6e4wkYOn3XmiITt/hEVH4TFMYvAX2Ytz6k=
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package auth
2+
3+
import (
4+
"errors"
5+
"os"
6+
"path/filepath"
7+
"strings"
8+
)
9+
10+
type fileTokenStorage struct {
11+
path string
12+
lockPath string
13+
}
14+
15+
func newFileTokenStorage(configDir string) *fileTokenStorage {
16+
return &fileTokenStorage{
17+
path: filepath.Join(configDir, "auth-token"),
18+
lockPath: filepath.Join(configDir, "auth-token.lock"),
19+
}
20+
}
21+
22+
func (f *fileTokenStorage) withLock(fn func() error) error {
23+
if err := os.MkdirAll(filepath.Dir(f.lockPath), 0700); err != nil {
24+
return err
25+
}
26+
lf, err := os.OpenFile(f.lockPath, os.O_CREATE|os.O_WRONLY, 0600)
27+
if err != nil {
28+
return err
29+
}
30+
defer func() { _ = lf.Close() }()
31+
32+
if err := lockFile(lf); err != nil {
33+
return err
34+
}
35+
defer func() { _ = unlockFile(lf) }()
36+
37+
return fn()
38+
}
39+
40+
func (f *fileTokenStorage) GetAuthToken() (string, error) {
41+
var token string
42+
err := f.withLock(func() error {
43+
data, err := os.ReadFile(f.path)
44+
if err != nil {
45+
if errors.Is(err, os.ErrNotExist) {
46+
return ErrTokenNotFound
47+
}
48+
return err
49+
}
50+
token = strings.TrimSpace(string(data))
51+
return nil
52+
})
53+
return token, err
54+
}
55+
56+
func (f *fileTokenStorage) SetAuthToken(token string) error {
57+
return f.withLock(func() error {
58+
if err := os.MkdirAll(filepath.Dir(f.path), 0700); err != nil {
59+
return err
60+
}
61+
return os.WriteFile(f.path, []byte(token), 0600)
62+
})
63+
}
64+
65+
func (f *fileTokenStorage) DeleteAuthToken() error {
66+
return f.withLock(func() error {
67+
err := os.Remove(f.path)
68+
if errors.Is(err, os.ErrNotExist) {
69+
return nil
70+
}
71+
return err
72+
})
73+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package auth
2+
3+
import (
4+
"os"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
func TestFileTokenStorage_SetGetDelete(t *testing.T) {
12+
dir := t.TempDir()
13+
s := newFileTokenStorage(dir)
14+
15+
require.NoError(t, s.SetAuthToken("my-token"))
16+
17+
got, err := s.GetAuthToken()
18+
require.NoError(t, err)
19+
assert.Equal(t, "my-token", got)
20+
21+
require.NoError(t, s.DeleteAuthToken())
22+
23+
_, err = s.GetAuthToken()
24+
assert.ErrorIs(t, err, ErrTokenNotFound)
25+
}
26+
27+
func TestFileTokenStorage_GetReturnsErrTokenNotFoundWhenNoFile(t *testing.T) {
28+
dir := t.TempDir()
29+
s := newFileTokenStorage(dir)
30+
31+
_, err := s.GetAuthToken()
32+
assert.ErrorIs(t, err, ErrTokenNotFound)
33+
}
34+
35+
func TestFileTokenStorage_DeleteIsIdempotent(t *testing.T) {
36+
dir := t.TempDir()
37+
s := newFileTokenStorage(dir)
38+
39+
assert.NoError(t, s.DeleteAuthToken())
40+
assert.NoError(t, s.DeleteAuthToken())
41+
}
42+
43+
func TestFileTokenStorage_FilePermissions(t *testing.T) {
44+
dir := t.TempDir()
45+
s := newFileTokenStorage(dir)
46+
47+
require.NoError(t, s.SetAuthToken("secret"))
48+
49+
info, err := os.Stat(s.path)
50+
require.NoError(t, err)
51+
assert.Equal(t, os.FileMode(0600), info.Mode().Perm())
52+
}

internal/auth/filelock_unix.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//go:build !windows
2+
3+
package auth
4+
5+
import (
6+
"os"
7+
"syscall"
8+
)
9+
10+
func lockFile(f *os.File) error {
11+
return syscall.Flock(int(f.Fd()), syscall.LOCK_EX)
12+
}
13+
14+
func unlockFile(f *os.File) error {
15+
return syscall.Flock(int(f.Fd()), syscall.LOCK_UN)
16+
}

internal/auth/filelock_windows.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//go:build windows
2+
3+
package auth
4+
5+
import "os"
6+
7+
func lockFile(f *os.File) error {
8+
// Windows LockFileEx requires unsafe/syscall wiring; for now token
9+
// file contention on Windows is unlikely enough to skip locking.
10+
return nil
11+
}
12+
13+
func unlockFile(f *os.File) error {
14+
return nil
15+
}

0 commit comments

Comments
 (0)