Skip to content

Commit e859f45

Browse files
authored
Merge pull request #23 from go-seatbelt/seatbelt/favour-secret-env-var
seatbelt: favour secret env var over master.key
2 parents 2fd9ab7 + 3eb4f79 commit e859f45

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,19 @@ jobs:
1010
test:
1111
strategy:
1212
matrix:
13-
go-version: [ 1.18.x, 1.19.x ]
13+
go-version: [ 1.23.x, 1.24.x ]
1414
os: [ ubuntu-latest, macos-latest, windows-latest ]
1515
runs-on: ${{ matrix.os }}
16+
1617
steps:
1718
- name: Install Go
1819
uses: actions/setup-go@v2
1920
with:
2021
go-version: ${{ matrix.go-version }}
22+
2123
- name: Checkout code
2224
uses: actions/checkout@v2
23-
- name: Restore cache
24-
uses: actions/cache@v2
25-
with:
26-
path: ~/go/pkg/mod
27-
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
28-
restore-keys: |
29-
${{ runner.os }}-go-
25+
3026
- name: Format
3127
run: if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then exit 1; fi
3228
if: matrix.os == 'ubuntu-latest'

seatbelt.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,16 +330,19 @@ func (o *Option) setDefaults() {
330330
// The "master.key" file is a secret and should be treated as such. It should
331331
// not be checked into your source code, and in production, the "SECRET"
332332
// environment variable should instead be used.
333+
//
334+
// The "SECRET" environment variable takes precendence over the "master.key"
335+
// file.
333336
func (o *Option) setMasterKey() {
334-
if key := os.Getenv("SECRET"); key != "" {
335-
o.SigningKey = key
336-
}
337-
338337
if key, err := os.ReadFile("master.key"); err == nil {
339338
o.SigningKey = string(key)
340339
return
341340
}
342341

342+
if key := os.Getenv("SECRET"); key != "" {
343+
o.SigningKey = key
344+
}
345+
343346
b := make([]byte, 32)
344347
if _, err := rand.Read(b); err != nil {
345348
panic(fmt.Sprintf("seatbelt: failed to read from source of randomness while generating master.key: %v", err))

0 commit comments

Comments
 (0)