v3.3.1 31f1eec

app_secret_files.go RawHistoryFolder

1package domain
2
3import (
4	"fmt"
5	"path"
6	"slices"
7	"strings"
8)
9
10// AppSecretFileDir is the container directory holding file-delivered secrets.
11const AppSecretFileDir = "/run/secrets"
12
13// SecretFileEnvKey returns the env key that points to a file-delivered secret.
14func SecretFileEnvKey(key string) string { return key + "_FILE" }
15
16// SecretFilePath returns the container path of a file-delivered secret.
17func SecretFilePath(key string) string { return AppSecretFileDir + "/" + key }
18
19// SecretAsFile reports whether the secret env key is delivered as a file.
20func (s AppService) SecretAsFile(key string) bool {
21	return slices.Contains(s.SecretFiles, key)
22}
23
24// validateSecretFiles checks the file-delivered secret keys of one service.
25// <KEY>_FILE collisions with public env are checked by
26// checkEnvSecretKeyDisjoint, which sees both app and service env.
27func (s *AppService) validateSecretFiles() error {
28	if !slices.IsSorted(s.SecretFiles) {
29		return fmt.Errorf("%w: service %q secret file keys must be sorted", ErrInvalidAppSpec, s.Name)
30	}
31	seen := make(map[string]struct{}, len(s.SecretFiles))
32	for _, key := range s.SecretFiles {
33		if _, ok := s.Secrets[key]; !ok {
34			return fmt.Errorf("%w: service %q secret file key %q is not a declared secret", ErrInvalidAppSpec, s.Name, key)
35		}
36		if _, dup := seen[key]; dup {
37			return fmt.Errorf("%w: service %q secret file key %q is duplicated", ErrInvalidAppSpec, s.Name, key)
38		}
39		seen[key] = struct{}{}
40		fileKey := SecretFileEnvKey(key)
41		if _, ok := s.Secrets[fileKey]; ok {
42			return fmt.Errorf("%w: service %q secret key %q collides with a secret file key", ErrInvalidAppSpec, s.Name, fileKey)
43		}
44	}
45	if len(s.SecretFiles) == 0 {
46		return nil
47	}
48	for _, b := range s.Binds {
49		if underSecretFileDir(b.Path) {
50			return fmt.Errorf("%w: service %q bind %q must not mount at or under %s when secrets are delivered as files", ErrInvalidAppSpec, s.Name, b.Name, AppSecretFileDir)
51		}
52	}
53	for _, v := range s.Volumes {
54		if underSecretFileDir(v.Path) {
55			return fmt.Errorf("%w: service %q volume %q must not mount at or under %s when secrets are delivered as files", ErrInvalidAppSpec, s.Name, v.Name, AppSecretFileDir)
56		}
57	}
58	return nil
59}
60
61func underSecretFileDir(p string) bool {
62	p = path.Clean(p)
63	return p == AppSecretFileDir || strings.HasPrefix(p, AppSecretFileDir+"/")
64}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close