@@ -50,6 +50,10 @@ const (
5050 regexLabelPattern = "^[a-zA-Z0-9]([a-zA-Z0-9-_.]{0,254}[a-zA-Z0-9])?$"
5151)
5252
53+ var domainRegex = regexp .MustCompile (
54+ `^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$` ,
55+ )
56+
5357var viperInstance = viper .NewWithOptions (viper .KeyDelimiter (KeyDelimiter ))
5458
5559func RegisterRunner (r func (cmd * cobra.Command , args []string )) {
@@ -158,6 +162,7 @@ func ResolveConfig() (*Config, error) {
158162 Labels : resolveLabels (),
159163 LibDir : viperInstance .GetString (LibDirPathKey ),
160164 SyslogServer : resolveSyslogServer (),
165+ ExternalDataSource : resolveExternalDataSource (),
161166 }
162167
163168 defaultCollector (collector , config )
@@ -475,6 +480,7 @@ func registerFlags() {
475480 registerCollectorFlags (fs )
476481 registerClientFlags (fs )
477482 registerDataPlaneFlags (fs )
483+ registerExternalDataSourceFlags (fs )
478484
479485 fs .SetNormalizeFunc (normalizeFunc )
480486
@@ -489,6 +495,29 @@ func registerFlags() {
489495 })
490496}
491497
498+ func registerExternalDataSourceFlags (fs * flag.FlagSet ) {
499+ fs .String (
500+ ExternalDataSourceProxyUrlKey ,
501+ DefExternalDataSourceProxyUrl ,
502+ "Url to the proxy service for fetching external files." ,
503+ )
504+ fs .StringSlice (
505+ ExternalDataSourceAllowDomainsKey ,
506+ []string {},
507+ "List of allowed domains for external data sources." ,
508+ )
509+ fs .StringSlice (
510+ ExternalDataSourceAllowedFileTypesKey ,
511+ []string {},
512+ "List of allowed file types for external data sources." ,
513+ )
514+ fs .Int64 (
515+ ExternalDataSourceMaxBytesKey ,
516+ DefExternalDataSourceMaxBytes ,
517+ "Maximum size in bytes for external data sources." ,
518+ )
519+ }
520+
492521func registerDataPlaneFlags (fs * flag.FlagSet ) {
493522 fs .Duration (
494523 NginxReloadMonitoringPeriodKey ,
@@ -646,6 +675,11 @@ func registerClientFlags(fs *flag.FlagSet) {
646675 DefMaxParallelFileOperations ,
647676 "Maximum number of file downloads or uploads performed in parallel" ,
648677 )
678+ fs .Duration (
679+ ClientFileDownloadTimeoutKey ,
680+ DefClientFileDownloadTimeout ,
681+ "Timeout value in seconds, for downloading a file during a config apply." ,
682+ )
649683}
650684
651685func registerCommandFlags (fs * flag.FlagSet ) {
@@ -1134,6 +1168,7 @@ func resolveClient() *Client {
11341168 RandomizationFactor : viperInstance .GetFloat64 (ClientBackoffRandomizationFactorKey ),
11351169 Multiplier : viperInstance .GetFloat64 (ClientBackoffMultiplierKey ),
11361170 },
1171+ FileDownloadTimeout : viperInstance .GetDuration (ClientFileDownloadTimeoutKey ),
11371172 }
11381173}
11391174
@@ -1574,3 +1609,37 @@ func areCommandServerProxyTLSSettingsSet() bool {
15741609 viperInstance .IsSet (CommandServerProxyTLSSkipVerifyKey ) ||
15751610 viperInstance .IsSet (CommandServerProxyTLSServerNameKey )
15761611}
1612+
1613+ func resolveExternalDataSource () * ExternalDataSource {
1614+ proxyURLStruct := ProxyURL {
1615+ URL : viperInstance .GetString (ExternalDataSourceProxyUrlKey ),
1616+ }
1617+ externalDataSource := & ExternalDataSource {
1618+ ProxyURL : proxyURLStruct ,
1619+ AllowedDomains : viperInstance .GetStringSlice (ExternalDataSourceAllowDomainsKey ),
1620+ AllowedFileTypes : viperInstance .GetStringSlice (ExternalDataSourceAllowedFileTypesKey ),
1621+ MaxBytes : viperInstance .GetInt64 (ExternalDataSourceMaxBytesKey ),
1622+ }
1623+
1624+ if err := validateAllowedDomains (externalDataSource .AllowedDomains ); err != nil {
1625+ slog .Error ("External data source not configured due to invalid configuration" , "error" , err )
1626+ return nil
1627+ }
1628+
1629+ return externalDataSource
1630+ }
1631+
1632+ func validateAllowedDomains (domains []string ) error {
1633+ if len (domains ) == 0 {
1634+ return nil
1635+ }
1636+
1637+ for _ , domain := range domains {
1638+ // Validating syntax using the RFC-compliant regex
1639+ if ! domainRegex .MatchString (domain ) || domain == "" {
1640+ return errors .New ("invalid domain found in allowed_domains" )
1641+ }
1642+ }
1643+
1644+ return nil
1645+ }
0 commit comments