Skip to content

Commit 08811bf

Browse files
committed
Merge branch 'main' into update-crossplane
2 parents 0c82500 + c5193ee commit 08811bf

File tree

10 files changed

+480
-97
lines changed

10 files changed

+480
-97
lines changed

.github/workflows/release-branch.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ jobs:
9696
ref: ${{ inputs.releaseBranch }}
9797

9898
- name: Setup Node Environment
99-
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
99+
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
100100

101101
- name: Create Draft Release
102102
if: ${{ needs.vars.outputs.github_release == 'true' }}

.github/workflows/scorecards.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ jobs:
5555

5656
# Upload the results to GitHub's code scanning dashboard.
5757
- name: "Upload to code-scanning"
58-
uses: github/codeql-action/upload-sarif@f443b600d91635bebf5b0d9ebc620189c0d6fba5 # v4.30.8
58+
uses: github/codeql-action/upload-sarif@16140ae1a102900babc80a33c44059580f687047 # v4.30.9
5959
with:
6060
sarif_file: results.sarif

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ require (
4747
go.opentelemetry.io/collector/component v1.43.0
4848
go.opentelemetry.io/collector/component/componenttest v0.137.0
4949
go.opentelemetry.io/collector/config/confighttp v0.136.0
50-
go.opentelemetry.io/collector/confmap v1.43.0
50+
go.opentelemetry.io/collector/confmap v1.44.0
5151
go.opentelemetry.io/collector/confmap/provider/envprovider v1.42.0
5252
go.opentelemetry.io/collector/confmap/provider/fileprovider v1.42.0
5353
go.opentelemetry.io/collector/confmap/provider/httpprovider v1.42.0
@@ -63,7 +63,7 @@ require (
6363
go.opentelemetry.io/collector/extension v1.43.0
6464
go.opentelemetry.io/collector/extension/extensionauth v1.42.0
6565
go.opentelemetry.io/collector/extension/xextension v0.137.0
66-
go.opentelemetry.io/collector/filter v0.136.0
66+
go.opentelemetry.io/collector/filter v0.138.0
6767
go.opentelemetry.io/collector/otelcol v0.136.0
6868
go.opentelemetry.io/collector/pdata v1.43.0
6969
go.opentelemetry.io/collector/processor v1.42.0
@@ -290,7 +290,7 @@ require (
290290
go.opentelemetry.io/collector/extension/extensionmiddleware v0.136.0 // indirect
291291
go.opentelemetry.io/collector/extension/extensiontest v0.137.0 // indirect
292292
go.opentelemetry.io/collector/extension/zpagesextension v0.136.0 // indirect
293-
go.opentelemetry.io/collector/featuregate v1.43.0 // indirect
293+
go.opentelemetry.io/collector/featuregate v1.44.0 // indirect
294294
go.opentelemetry.io/collector/internal/fanoutconsumer v0.136.0 // indirect
295295
go.opentelemetry.io/collector/internal/memorylimiter v0.136.0 // indirect
296296
go.opentelemetry.io/collector/internal/sharedcomponent v0.136.0 // indirect

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -744,8 +744,8 @@ go.opentelemetry.io/collector/config/configtelemetry v0.137.0 h1:+QwfFnMwb5UatXY
744744
go.opentelemetry.io/collector/config/configtelemetry v0.137.0/go.mod h1:Xjw2+DpNLjYtx596EHSWBy0dNQRiJ2H+BlWU907lO40=
745745
go.opentelemetry.io/collector/config/configtls v1.42.0 h1:gACpOXSmxBeo+M8qjSxt7AU04B0qWzjqg2ZLvMA8Sdo=
746746
go.opentelemetry.io/collector/config/configtls v1.42.0/go.mod h1:SJNnptQLBW+nO4CgTtNI1di8nAHNOIl2gclu9GsmK8g=
747-
go.opentelemetry.io/collector/confmap v1.43.0 h1:QVAnbS7A+2Ra61xsuG355vhlW6uOMaKWysrwLQzDUz4=
748-
go.opentelemetry.io/collector/confmap v1.43.0/go.mod h1:N5GZpFCmwD1GynDu3IWaZW5Ycfc/7YxSU0q1/E3vLdg=
747+
go.opentelemetry.io/collector/confmap v1.44.0 h1:CIK4jAk6H3KTKza4nvWQkqLqrudLkYGz3evu5163uxg=
748+
go.opentelemetry.io/collector/confmap v1.44.0/go.mod h1:w37Xiu/PK3nTdqKb7YEvQECHYkuW7QnmdS7b9iRjOGo=
749749
go.opentelemetry.io/collector/confmap/provider/envprovider v1.42.0 h1:I4ijuuEUBtePNu7v3C8S/uwEwcXsQnos6d/lvCKby6k=
750750
go.opentelemetry.io/collector/confmap/provider/envprovider v1.42.0/go.mod h1:Nd5diM9jWG9sg6d6eHvR3sIuYgnU9PptExuCgELKTIs=
751751
go.opentelemetry.io/collector/confmap/provider/fileprovider v1.42.0 h1:BGejutI9811qBuzlV9jUI0vOLLR/6P/yprn4HqrQkh4=
@@ -808,10 +808,10 @@ go.opentelemetry.io/collector/extension/xextension v0.137.0 h1:UQ/I7D5/YmkvAV7g8
808808
go.opentelemetry.io/collector/extension/xextension v0.137.0/go.mod h1:T2Vr5ijSNW7PavuyZyRYYxCitpUTN+f4tRUdED/rtRw=
809809
go.opentelemetry.io/collector/extension/zpagesextension v0.136.0 h1:acfmAXEGmvLlM2N6KtieLVKXBvJ/dmkOfOFDftZFFXg=
810810
go.opentelemetry.io/collector/extension/zpagesextension v0.136.0/go.mod h1:fXFm8bNm6QegoFjFk3QINvSXUDyBSy/3r/mv366xQ5A=
811-
go.opentelemetry.io/collector/featuregate v1.43.0 h1:Aq8UR5qv1zNlbbkTyqv8kLJtnoQMq/sG1/jS9o1cCJI=
812-
go.opentelemetry.io/collector/featuregate v1.43.0/go.mod h1:d0tiRzVYrytB6LkcYgz2ESFTv7OktRPQe0QEQcPt1L4=
813-
go.opentelemetry.io/collector/filter v0.136.0 h1:xomBHwwzOfejHvFBlR6ARijTh9nKXLsxj9BAqhr/FTc=
814-
go.opentelemetry.io/collector/filter v0.136.0/go.mod h1:k+ifbjV59jKq68abvPub7h307P9n5bl7WMWiQco5Pz0=
811+
go.opentelemetry.io/collector/featuregate v1.44.0 h1:/GeGhTD8f+FNWS7C4w1Dj0Ui9Jp4v2WAdlXyW1p3uG8=
812+
go.opentelemetry.io/collector/featuregate v1.44.0/go.mod h1:d0tiRzVYrytB6LkcYgz2ESFTv7OktRPQe0QEQcPt1L4=
813+
go.opentelemetry.io/collector/filter v0.138.0 h1:8gqk74hX4Sp7crUScUL89Eoa9ieDOpJJ+MtxLPKtpps=
814+
go.opentelemetry.io/collector/filter v0.138.0/go.mod h1:vLSR5hAupTYEDk0Cqh8eu7TA76bKIZTxxwdxuAzxXN0=
815815
go.opentelemetry.io/collector/internal/fanoutconsumer v0.136.0 h1:GxjQ+9q6M7PwE3QnA3VVBLt5aHVnk4z7wQLo+J+0tho=
816816
go.opentelemetry.io/collector/internal/fanoutconsumer v0.136.0/go.mod h1:DOvL5ZalQk/zmYBjKZok52dXIxUOK0JoOoQfm5qjbhM=
817817
go.opentelemetry.io/collector/internal/memorylimiter v0.136.0 h1:7UDraAoCISvKiOY1o+F68NdjMTi55mOiZ8s51HtnX6o=

internal/config/config.go

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ const (
4646

4747
// Regular expression to match invalid characters in paths.
4848
// It matches whitespace, control characters, non-printable characters, and specific Unicode characters.
49-
regexInvalidPath = "\\s|[[:cntrl:]]|[[:space:]]|[[^:print:]]|ㅤ|\\.\\.|\\*"
49+
regexInvalidPath = "\\s|[[:cntrl:]]|[[:space:]]|[[^:print:]]|ㅤ|\\.\\.|\\*"
50+
regexLabelPattern = "^[a-zA-Z0-9]([a-zA-Z0-9-_]{0,254}[a-zA-Z0-9])?$"
5051
)
5152

5253
var viperInstance = viper.NewWithOptions(viper.KeyDelimiter(KeyDelimiter))
@@ -63,6 +64,40 @@ func Execute(ctx context.Context) error {
6364
func Init(version, commit string) {
6465
setVersion(version, commit)
6566
registerFlags()
67+
checkDeprecatedEnvVars()
68+
}
69+
70+
func checkDeprecatedEnvVars() {
71+
allViperKeys := make(map[string]struct{})
72+
for _, key := range viperInstance.AllKeys() {
73+
allViperKeys[key] = struct{}{}
74+
}
75+
76+
const v3Prefix = EnvPrefix + KeyDelimiter
77+
78+
for _, env := range os.Environ() {
79+
parts := strings.SplitN(env, "=", KeyValueNumber)
80+
if len(parts) != KeyValueNumber {
81+
continue
82+
}
83+
envKey := parts[0]
84+
85+
if !strings.HasPrefix(envKey, v3Prefix) {
86+
continue
87+
}
88+
89+
viperKey := strings.TrimPrefix(envKey, v3Prefix)
90+
91+
viperKey = strings.ToLower(viperKey)
92+
93+
if _, exists := allViperKeys[viperKey]; !exists {
94+
slog.Warn("Detected deprecated or unknown environment variables. "+
95+
"Please update to use the latest environment variables. For more information, visit "+
96+
"https://docs.nginx.com/nginx-one/agent/configure-instances/configuration-overview/.",
97+
"deprecated_env_var", envKey,
98+
)
99+
}
100+
}
66101
}
67102

68103
func RegisterConfigFile() error {
@@ -946,7 +981,9 @@ func resolveLabels() map[string]interface{} {
946981
result[trimmedKey] = parseJSON(trimmedValue)
947982

948983
default: // String
949-
result[trimmedKey] = trimmedValue
984+
if validateLabel(trimmedValue) {
985+
result[trimmedKey] = trimmedValue
986+
}
950987
}
951988
}
952989

@@ -955,6 +992,19 @@ func resolveLabels() map[string]interface{} {
955992
return result
956993
}
957994

995+
func validateLabel(labelValue string) bool {
996+
const maxLength = 256
997+
labelPattern := regexp.MustCompile(regexLabelPattern)
998+
if len(labelValue) > maxLength || !labelPattern.MatchString(labelValue) {
999+
slog.Warn("Label value contains unsupported character or exceed maximum length of 256 characters ",
1000+
"label_value", labelValue)
1001+
1002+
return false
1003+
}
1004+
1005+
return true
1006+
}
1007+
9581008
func resolveEnvironmentVariableLabels() map[string]string {
9591009
envLabels := make(map[string]string)
9601010
envInput := viperInstance.GetString(LabelsRootKey)

internal/config/config_test.go

Lines changed: 154 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
package config
66

77
import (
8+
"bytes"
89
_ "embed"
910
"errors"
11+
"log/slog"
1012
"os"
1113
"path"
1214
"sort"
@@ -164,6 +166,100 @@ func TestNormalizeFunc(t *testing.T) {
164166
assert.Equal(t, expected, result)
165167
}
166168

169+
type deprecatedEnvVarsTest struct {
170+
name string
171+
expectedLogContent string
172+
unexpectedLogContent string
173+
envVars map[string]string
174+
viperKeys []string
175+
expectWarning bool
176+
}
177+
178+
func TestCheckDeprecatedEnvVars(t *testing.T) {
179+
tests := []deprecatedEnvVarsTest{
180+
{
181+
name: "Test 1: should log warning for deprecated env var",
182+
envVars: map[string]string{
183+
"NGINX_AGENT_SERVER_HOST": "value",
184+
},
185+
viperKeys: []string{"some_other_key"},
186+
expectedLogContent: "NGINX_AGENT_SERVER_HOST",
187+
expectWarning: true,
188+
},
189+
{
190+
name: "Test 2: should not log warning for valid env var",
191+
envVars: map[string]string{
192+
"NGINX_AGENT_LOG_LEVEL": "info",
193+
},
194+
viperKeys: []string{"log_level"},
195+
unexpectedLogContent: "NGINX_AGENT_LOG_LEVEL",
196+
expectWarning: false,
197+
},
198+
{
199+
name: "Test 3: should handle mixed valid and deprecated env vars",
200+
envVars: map[string]string{
201+
"NGINX_AGENT_LOG_LEVEL": "info",
202+
"NGINX_AGENT_DEPRECATED_VAR": "value",
203+
},
204+
viperKeys: []string{"log_level"},
205+
expectedLogContent: "NGINX_AGENT_DEPRECATED_VAR",
206+
unexpectedLogContent: "NGINX_AGENT_LOG_LEVEL",
207+
expectWarning: true,
208+
},
209+
{
210+
name: "Test 4: should ignore non-agent env vars",
211+
envVars: map[string]string{
212+
"NGINX_LICENSE": "value",
213+
},
214+
viperKeys: []string{},
215+
expectWarning: false,
216+
},
217+
}
218+
219+
for _, tc := range tests {
220+
t.Run(tc.name, func(t *testing.T) {
221+
runDeprecatedEnvVarsTest(t, tc)
222+
})
223+
}
224+
}
225+
226+
func runDeprecatedEnvVarsTest(t *testing.T, tc deprecatedEnvVarsTest) {
227+
t.Helper()
228+
229+
originalViper := viperInstance
230+
viperInstance = viper.NewWithOptions(viper.KeyDelimiter(KeyDelimiter))
231+
defer func() { viperInstance = originalViper }()
232+
233+
for key, value := range tc.envVars {
234+
t.Setenv(key, value)
235+
}
236+
237+
for _, key := range tc.viperKeys {
238+
viperInstance.Set(key, "any-value")
239+
}
240+
241+
var logBuffer bytes.Buffer
242+
handler := slog.NewTextHandler(&logBuffer, nil)
243+
slog.SetDefault(slog.New(handler))
244+
245+
checkDeprecatedEnvVars()
246+
247+
logOutput := logBuffer.String()
248+
249+
if tc.expectWarning {
250+
require.NotEmpty(t, logOutput, "Expected a warning log, but got none")
251+
assert.Contains(t, logOutput, "Detected deprecated or unknown environment variables")
252+
if tc.expectedLogContent != "" {
253+
assert.Contains(t, logOutput, tc.expectedLogContent)
254+
}
255+
if tc.unexpectedLogContent != "" {
256+
assert.NotContains(t, logOutput, tc.unexpectedLogContent)
257+
}
258+
} else {
259+
assert.Empty(t, logOutput, "Expected no warning logs")
260+
}
261+
}
262+
167263
func TestResolveAllowedDirectories(t *testing.T) {
168264
tests := []struct {
169265
name string
@@ -1237,7 +1333,7 @@ func createConfig() *Config {
12371333
{
12381334
Action: "insert",
12391335
Key: "label1",
1240-
Value: "label 1",
1336+
Value: "label-1",
12411337
},
12421338
{
12431339
Action: "insert",
@@ -1317,7 +1413,7 @@ func createConfig() *Config {
13171413
},
13181414
},
13191415
Labels: map[string]any{
1320-
"label1": "label 1",
1416+
"label1": "label-1",
13211417
"label2": "new-value",
13221418
"label3": 123,
13231419
},
@@ -1413,3 +1509,59 @@ func createDefaultCollectorConfig() *Collector {
14131509
},
14141510
}
14151511
}
1512+
1513+
func TestValidateLabel(t *testing.T) {
1514+
tests := []struct {
1515+
name string
1516+
input string
1517+
expected bool
1518+
}{
1519+
{
1520+
name: "Test 1: Valid label - simple",
1521+
input: "label123",
1522+
expected: true,
1523+
},
1524+
{
1525+
name: "Test 2: Valid label - with dash and underscore",
1526+
input: "label-123_abc",
1527+
expected: true,
1528+
},
1529+
{
1530+
name: "Test 3: Invalid label - too long",
1531+
input: strings.Repeat("a", 257),
1532+
expected: false,
1533+
},
1534+
{
1535+
name: "Test 4: Invalid label - special char",
1536+
input: "label$",
1537+
expected: false,
1538+
},
1539+
{
1540+
name: "Test 5: Invalid label - starts with dash",
1541+
input: "-label",
1542+
expected: false,
1543+
},
1544+
{
1545+
name: "Test 6: Invalid label - ends with dash",
1546+
input: "label-",
1547+
expected: false,
1548+
},
1549+
{
1550+
name: "Test 7: Invalid label - empty",
1551+
input: "",
1552+
expected: false,
1553+
},
1554+
{
1555+
name: "Test 8: Invalid label - contains spaces",
1556+
input: "label 123",
1557+
expected: false,
1558+
},
1559+
}
1560+
1561+
for _, tt := range tests {
1562+
t.Run(tt.name, func(t *testing.T) {
1563+
actual := validateLabel(tt.input)
1564+
assert.Equal(t, tt.expected, actual)
1565+
})
1566+
}
1567+
}

internal/config/testdata/nginx-agent.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ watchers:
1313
- \.*log$
1414

1515
labels:
16-
label1: label 1
16+
label1: label-1
1717
label2: new-value
1818
label3: 123
1919

0 commit comments

Comments
 (0)