Skip to content

Commit 7dd802e

Browse files
committed
rhel: don't consider hyphen as valid in dockerfile ENV var names
This change means label values like `"$PRODNAME-$COMPNAME-container"` will be expanded to something like `"rhdh-hub-container"` instead of `""` which I think is preferred as the security data refers to "rhdh-hub-container" as the package_name. Signed-off-by: crozzy <joseph.crosland@gmail.com>
1 parent 4330f41 commit 7dd802e

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

rhel/dockerfile/vars.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func (v *Vars) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error
209209

210210
// ValidName tests whether the rune is valid in a variable name.
211211
func validName(r rune) bool {
212-
return unicode.In(r, unicode.Letter, unicode.Digit) || r == '_' || r == '-'
212+
return unicode.In(r, unicode.Letter, unicode.Digit) || r == '_'
213213
}
214214

215215
// Emit writes out the expanded variable, using state accumulated in the

rhel/dockerfile/vars_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ func TestVars(t *testing.T) {
110110
SrcSz: 10,
111111
Setup: setX,
112112
},
113+
{
114+
Name: "Hyphen",
115+
In: `$X-$X`,
116+
Out: `expand-expand`,
117+
SpanSz: 0,
118+
SpanErr: transform.ErrEndOfSpan,
119+
SrcSz: 5,
120+
Setup: setX,
121+
},
113122
}
114123
// TODO(hank) Need to hit the various corner error cases.
115124
t.Run("Span", func(t *testing.T) {

rhel/rhcc/scanner_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@ func TestContainerScanner(t *testing.T) {
6060
RepositoryHint: "rhcc",
6161
Arch: "x86_64",
6262
}
63+
rhdhSourceContainer := &claircore.Package{
64+
Name: "rhdh-hub-container",
65+
Version: "1.3-100",
66+
NormalizedVersion: claircore.Version{
67+
Kind: "rhctag",
68+
V: [10]int32{1, 3},
69+
},
70+
Kind: claircore.SOURCE,
71+
PackageDB: "root/buildinfo/Dockerfile-rhdh-rhdh-hub-rhel9-1.3-100",
72+
RepositoryHint: "rhcc",
73+
Arch: "x86_64",
74+
}
75+
6376
name2reposData := map[string]map[string][]string{
6477
"data": {"openshift/ose-logging-elasticsearch6": {"openshift4/ose-logging-elasticsearch6"}},
6578
}
@@ -130,6 +143,26 @@ func TestContainerScanner(t *testing.T) {
130143
},
131144
},
132145
},
146+
{
147+
Name: "RHDH",
148+
Dockerfile: "testdata/Dockerfile-rhdh-rhdh-hub-rhel9-1.3-100",
149+
Want: []*claircore.Package{
150+
rhdhSourceContainer,
151+
{
152+
Name: "rhdh/rhdh-hub-rhel9",
153+
Version: "1.3-100",
154+
NormalizedVersion: claircore.Version{
155+
Kind: "rhctag",
156+
V: [10]int32{1, 3},
157+
},
158+
Kind: claircore.BINARY,
159+
Source: rhdhSourceContainer,
160+
PackageDB: "root/buildinfo/Dockerfile-rhdh-rhdh-hub-rhel9-1.3-100",
161+
RepositoryHint: "rhcc",
162+
Arch: "x86_64",
163+
},
164+
},
165+
},
133166
}
134167
mux := http.NewServeMux()
135168
mux.HandleFunc("/container-name-repos-map.json", func(w http.ResponseWriter, _ *http.Request) {

0 commit comments

Comments
 (0)