Skip to content

Commit 4802af9

Browse files
committed
Encrypt secrets using the template function secret
1 parent 57c7614 commit 4802af9

File tree

10 files changed

+530
-135
lines changed

10 files changed

+530
-135
lines changed

e2e/e2e_test.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ import (
44
"bytes"
55
"context"
66
"fmt"
7+
"io"
78
"net/http"
89
"net/http/httptest"
910
"os"
1011
"testing"
1112
"time"
1213

1314
"github.com/fortnoxab/gitmachinecontroller/pkg/admin"
15+
"github.com/fortnoxab/gitmachinecontroller/pkg/api/v1/types"
16+
"github.com/fortnoxab/gitmachinecontroller/pkg/secrets"
1417
"github.com/sirupsen/logrus"
1518
"github.com/stretchr/testify/assert"
1619
)
@@ -214,7 +217,7 @@ spec:
214217
err = a.Exec(context.TODO(), "uptime")
215218
assert.Equal(t, "websocket: bad handshake", err.Error())
216219

217-
assert.Contains(t, buf.String(), "Error #01: auth: error validating")
220+
assert.Contains(t, buf.String(), "http_request_status=401")
218221
cancel()
219222
c.wg.Wait()
220223
}
@@ -379,3 +382,30 @@ spec:
379382
cancel()
380383
c.wg.Wait()
381384
}
385+
386+
func TestMasterEncryptString(t *testing.T) {
387+
388+
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
389+
defer cancel()
390+
c := initMasterAgent(t, ctx)
391+
392+
resp, err := c.client.Post("/api/secret-encrypt-v1", bytes.NewBufferString(`mysecretstring`))
393+
assert.NoError(t, err)
394+
defer resp.Body.Close()
395+
396+
b, err := io.ReadAll(resp.Body)
397+
assert.NoError(t, err)
398+
399+
sh := secrets.NewHandler("asdfasdf")
400+
files := types.Files{
401+
{
402+
Content: fmt.Sprintf(`my cool test file content with {{secret "%s"}}`, string(b)),
403+
},
404+
}
405+
err = sh.DecryptFilesContent(files)
406+
assert.NoError(t, err)
407+
408+
assert.Equal(t, "my cool test file content with mysecretstring", files[0].Content)
409+
cancel()
410+
c.wg.Wait()
411+
}

e2e/utils_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func initMasterAgent(t *testing.T, ctx context.Context) testWrapper {
3838
GitPollInterval: time.Second,
3939
WsPort: portStr,
4040
JWTKey: "asdfasdf",
41+
SecretKey: "asdfasdf",
4142
Masters: config.Masters{
4243
{
4344
URL: "http://localhost:" + portStr,

go.mod

Lines changed: 78 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,82 +3,103 @@ module github.com/fortnoxab/gitmachinecontroller
33
go 1.23
44

55
require (
6-
github.com/fatih/color v1.13.0
7-
github.com/fluxcd/pkg/git v0.7.0
8-
github.com/fluxcd/pkg/git/gogit v0.3.1
6+
github.com/fatih/color v1.18.0
7+
github.com/fluxcd/pkg/git v0.21.0
8+
github.com/fluxcd/pkg/git/gogit v0.21.0
99
github.com/fortnoxab/ginprometheus v0.0.0-20211026110220-d3da4ce1dc2b
10-
github.com/gin-contrib/pprof v1.4.0
11-
github.com/gin-gonic/gin v1.8.1
12-
github.com/golang-jwt/jwt/v4 v4.4.3
10+
github.com/gin-contrib/pprof v1.5.1
11+
github.com/gin-gonic/gin v1.10.0
12+
github.com/golang-jwt/jwt/v4 v4.5.1
1313
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
14-
github.com/google/uuid v1.3.0
15-
github.com/gorilla/websocket v1.5.0
14+
github.com/google/uuid v1.6.0
15+
github.com/gorilla/websocket v1.5.3
1616
github.com/jonaz/ginlogrus v0.0.0-20191118094232-2f4da50f5dd6
17-
github.com/olahol/melody v1.1.1
18-
github.com/sirupsen/logrus v1.9.0
19-
github.com/stretchr/testify v1.9.0
20-
github.com/urfave/cli/v2 v2.23.7
17+
github.com/olahol/melody v1.2.1
18+
github.com/sirupsen/logrus v1.9.3
19+
github.com/stretchr/testify v1.10.0
20+
github.com/urfave/cli/v2 v2.27.5
2121
gopkg.in/yaml.v3 v3.0.1
22-
k8s.io/apimachinery v0.26.0
22+
k8s.io/apimachinery v0.31.3
2323
)
2424

2525
require (
26-
github.com/Masterminds/semver/v3 v3.2.0 // indirect
27-
github.com/Microsoft/go-winio v0.6.0 // indirect
28-
github.com/ProtonMail/go-crypto v0.0.0-20221026131551-cf6655e29de4 // indirect
29-
github.com/acomagu/bufpipe v1.0.3 // indirect
26+
dario.cat/mergo v1.0.1 // indirect
27+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.16.0 // indirect
28+
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.0 // indirect
29+
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect
30+
github.com/AzureAD/microsoft-authentication-library-for-go v1.3.2 // indirect
31+
github.com/Masterminds/semver/v3 v3.3.1 // indirect
32+
github.com/Microsoft/go-winio v0.6.2 // indirect
33+
github.com/ProtonMail/go-crypto v1.1.3 // indirect
34+
github.com/acomagu/bufpipe v1.0.4 // indirect
3035
github.com/beorn7/perks v1.0.1 // indirect
31-
github.com/cespare/xxhash/v2 v2.2.0 // indirect
32-
github.com/cloudflare/circl v1.3.0 // indirect
33-
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
34-
github.com/cyphar/filepath-securejoin v0.2.3 // indirect
35-
github.com/davecgh/go-spew v1.1.1 // indirect
36+
github.com/bytedance/sonic v1.12.5 // indirect
37+
github.com/bytedance/sonic/loader v0.2.1 // indirect
38+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
39+
github.com/cloudflare/circl v1.5.0 // indirect
40+
github.com/cloudwego/base64x v0.1.4 // indirect
41+
github.com/cloudwego/iasm v0.2.0 // indirect
42+
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
43+
github.com/cyphar/filepath-securejoin v0.3.4 // indirect
44+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
3645
github.com/emirpasic/gods v1.18.1 // indirect
37-
github.com/fluxcd/go-git/v5 v5.0.0-20221206140629-ec778c2c37df // indirect
38-
github.com/fluxcd/pkg/ssh v0.7.0 // indirect
39-
github.com/fluxcd/pkg/version v0.2.0 // indirect
46+
github.com/fluxcd/go-git/v5 v5.0.0-20221219190809-2e5c9d01cfc4 // indirect
47+
github.com/fluxcd/pkg/auth v0.0.1 // indirect
48+
github.com/fluxcd/pkg/ssh v0.14.1 // indirect
49+
github.com/fluxcd/pkg/version v0.4.1 // indirect
50+
github.com/gabriel-vasile/mimetype v1.4.7 // indirect
4051
github.com/gin-contrib/sse v0.1.0 // indirect
41-
github.com/go-git/gcfg v1.5.0 // indirect
42-
github.com/go-git/go-billy/v5 v5.3.1 // indirect
43-
github.com/go-logr/logr v1.2.3 // indirect
44-
github.com/go-playground/locales v0.14.0 // indirect
45-
github.com/go-playground/universal-translator v0.18.0 // indirect
46-
github.com/go-playground/validator/v10 v10.11.1 // indirect
47-
github.com/goccy/go-json v0.10.0 // indirect
48-
github.com/golang/protobuf v1.5.2 // indirect
49-
github.com/imdario/mergo v0.3.13 // indirect
52+
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
53+
github.com/go-git/go-billy/v5 v5.6.0 // indirect
54+
github.com/go-git/go-git/v5 v5.12.0 // indirect
55+
github.com/go-logr/logr v1.4.2 // indirect
56+
github.com/go-playground/locales v0.14.1 // indirect
57+
github.com/go-playground/universal-translator v0.18.1 // indirect
58+
github.com/go-playground/validator/v10 v10.23.0 // indirect
59+
github.com/goccy/go-json v0.10.3 // indirect
60+
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
61+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
62+
github.com/golang/protobuf v1.5.4 // indirect
63+
github.com/imdario/mergo v0.3.16 // indirect
5064
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
5165
github.com/json-iterator/go v1.1.12 // indirect
5266
github.com/kevinburke/ssh_config v1.2.0 // indirect
53-
github.com/leodido/go-urn v1.2.1 // indirect
54-
github.com/mattn/go-colorable v0.1.9 // indirect
55-
github.com/mattn/go-isatty v0.0.16 // indirect
67+
github.com/klauspost/compress v1.17.11 // indirect
68+
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
69+
github.com/kylelemons/godebug v1.1.0 // indirect
70+
github.com/leodido/go-urn v1.4.0 // indirect
71+
github.com/mattn/go-colorable v0.1.13 // indirect
72+
github.com/mattn/go-isatty v0.0.20 // indirect
5673
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
5774
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
5875
github.com/modern-go/reflect2 v1.0.2 // indirect
59-
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
60-
github.com/pjbgf/sha1cd v0.2.3 // indirect
61-
github.com/pmezard/go-difflib v1.0.0 // indirect
62-
github.com/prometheus/client_golang v1.14.0 // indirect
63-
github.com/prometheus/client_model v0.3.0 // indirect
64-
github.com/prometheus/common v0.38.0 // indirect
65-
github.com/prometheus/procfs v0.8.0 // indirect
76+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
77+
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
78+
github.com/pjbgf/sha1cd v0.3.0 // indirect
79+
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
80+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
81+
github.com/prometheus/client_golang v1.20.5 // indirect
82+
github.com/prometheus/client_model v0.6.1 // indirect
83+
github.com/prometheus/common v0.60.1 // indirect
84+
github.com/prometheus/procfs v0.15.1 // indirect
6685
github.com/russross/blackfriday/v2 v2.1.0 // indirect
67-
github.com/sergi/go-diff v1.2.0 // indirect
68-
github.com/skeema/knownhosts v1.1.0 // indirect
86+
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
87+
github.com/skeema/knownhosts v1.3.0 // indirect
6988
github.com/stretchr/objx v0.5.2 // indirect
70-
github.com/ugorji/go/codec v1.2.7 // indirect
89+
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
90+
github.com/ugorji/go/codec v1.2.12 // indirect
7191
github.com/xanzy/ssh-agent v0.3.3 // indirect
72-
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
73-
golang.org/x/crypto v0.4.0 // indirect
74-
golang.org/x/mod v0.7.0 // indirect
75-
golang.org/x/net v0.4.0 // indirect
76-
golang.org/x/sys v0.3.0 // indirect
77-
golang.org/x/text v0.5.0 // indirect
78-
golang.org/x/tools v0.4.0 // indirect
79-
google.golang.org/protobuf v1.28.1 // indirect
92+
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
93+
golang.org/x/arch v0.12.0 // indirect
94+
golang.org/x/crypto v0.29.0 // indirect
95+
golang.org/x/mod v0.22.0 // indirect
96+
golang.org/x/net v0.31.0 // indirect
97+
golang.org/x/sys v0.27.0 // indirect
98+
golang.org/x/text v0.20.0 // indirect
99+
golang.org/x/tools v0.27.0 // indirect
100+
google.golang.org/protobuf v1.35.2 // indirect
80101
gopkg.in/warnings.v0 v0.1.2 // indirect
81102
gopkg.in/yaml.v2 v2.4.0 // indirect
82-
k8s.io/klog/v2 v2.80.1 // indirect
83-
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d // indirect
103+
k8s.io/klog/v2 v2.130.1 // indirect
104+
k8s.io/utils v0.0.0-20241104163129-6fe5fd82f078 // indirect
84105
)

0 commit comments

Comments
 (0)