Skip to content

Commit fdb70e0

Browse files
committed
add error message in applog-stream for syslog-drain validation
1 parent 83519ee commit fdb70e0

36 files changed

+1251
-335
lines changed

jobs/loggr-syslog-agent/templates/bpm.yml.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"PPROF_PORT" => "#{p("metrics.pprof_port")}",
3838
"USE_RFC3339" => "#{p("logging.format.timestamp") == "rfc3339"}",
3939
"WARN_ON_INVALID_DRAINS" => "#{p("warn_on_invalid_drains")}",
40+
"LOGGREGATOR_AGENT_ADDR" => "localhost:#{p('port')}",
4041
}
4142
}
4243
if_p("drain_cipher_suites") do | ciphers |

jobs/loggr-syslog-binding-cache/spec

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ templates:
1414
metrics.key.erb: config/certs/metrics.key
1515
aggregate_drains.yml.erb: config/aggregate_drains.yml
1616
prom_scraper_config.yml.erb: config/prom_scraper_config.yml
17+
agent.crt.erb: config/certs/agent.crt
18+
agent.key.erb: config/certs/agent.key
19+
agent_ca.crt.erb: config/certs/agent_ca.crt
1720

1821
packages:
1922
- binding-cache
@@ -134,3 +137,31 @@ properties:
134137
logging.format.timestamp:
135138
description: "Format for timestamp in component logs. Valid values are 'deprecated' and 'rfc3339'."
136139
default: "deprecated"
140+
141+
agent.port:
142+
description: "Port the agent is serving gRPC via mTLS"
143+
default: 3458
144+
agent.ca_cert:
145+
description: |
146+
TLS loggregator root CA certificate. It is required for key/cert
147+
verification.
148+
agent.cert:
149+
description: "TLS certificate for Syslog Binding Cache signed by the loggregator CA"
150+
agent.key:
151+
description: "TLS private key for Syslog Binding Cache signed by the loggregator CA"
152+
agent.cipher_suites:
153+
description: |
154+
An ordered list of supported SSL cipher suites. Allowed cipher suites are
155+
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 and TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384.
156+
default: "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"
157+
158+
blacklisted_syslog_ranges:
159+
description: |
160+
A list of IP address ranges that are not allowed to be specified in
161+
syslog drain binding URLs.
162+
default: []
163+
example: [{start: 10.10.10.1, end: 10.10.10.10}]
164+
165+
warn_on_invalid_drains:
166+
description: "Whether to output log warnings on invalid drains"
167+
default: true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%= p("agent.cert") %>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%= p("agent.key") %>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%= p("agent.ca_cert") %>

jobs/loggr-syslog-binding-cache/templates/bpm.yml.erb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
<%
2+
blacklisted_ranges = p("blacklisted_syslog_ranges")
3+
blacklisted_ips = blacklisted_ranges.map do |range|
4+
"#{range['start']}-#{range['end']}"
5+
end.join(",")
6+
27
certs_dir = "/var/vcap/jobs/loggr-syslog-binding-cache/config/certs"
38
api_url = link("cloud_controller").address
49
if_p("api.override_url") {
@@ -32,6 +37,15 @@
3237
"DEBUG_METRICS" => "#{p("metrics.debug")}",
3338
"PPROF_PORT" => "#{p("metrics.pprof_port")}",
3439
"USE_RFC3339" => "#{p("logging.format.timestamp") == "rfc3339"}",
40+
41+
"AGENT_CA_FILE_PATH" => "#{certs_dir}/agent_ca.crt",
42+
"AGENT_CERT_FILE_PATH" => "#{certs_dir}/agent.crt",
43+
"AGENT_KEY_FILE_PATH" => "#{certs_dir}/agent.key",
44+
"AGENT_CIPHER_SUITES" => "#{p("agent.cipher_suites").split(":").join(",")}",
45+
"AGENT_PORT" => "#{p("agent.port")}",
46+
"FORWARDER_AGENT_ADDR" => "localhost:#{p("agent.port")}",
47+
48+
"BLACKLISTED_SYSLOG_RANGES" => "#{blacklisted_ips}",
3549
}
3650
}
3751
bpm = {"processes" => [process] }

src/cmd/syslog-agent/app/config.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ import (
55
"strings"
66
"time"
77

8-
"code.cloudfoundry.org/loggregator-agent-release/src/pkg/config"
9-
"code.cloudfoundry.org/loggregator-agent-release/src/pkg/ingress/bindings"
10-
118
"code.cloudfoundry.org/go-envstruct"
9+
"code.cloudfoundry.org/loggregator-agent-release/src/pkg/binding/blacklist"
10+
"code.cloudfoundry.org/loggregator-agent-release/src/pkg/config"
1211
)
1312

1413
// GRPC stores the configuration for the router as a server using a PORT
@@ -22,25 +21,26 @@ type GRPC struct {
2221
}
2322

2423
type Cache struct {
25-
URL string `env:"CACHE_URL, report"`
26-
CAFile string `env:"CACHE_CA_FILE_PATH, report"`
27-
CertFile string `env:"CACHE_CERT_FILE_PATH, report"`
28-
KeyFile string `env:"CACHE_KEY_FILE_PATH, report"`
29-
CommonName string `env:"CACHE_COMMON_NAME, report"`
30-
PollingInterval time.Duration `env:"CACHE_POLLING_INTERVAL, report"`
31-
Blacklist bindings.BlacklistRanges `env:"BLACKLISTED_SYSLOG_RANGES, report"`
24+
URL string `env:"CACHE_URL, report"`
25+
CAFile string `env:"CACHE_CA_FILE_PATH, report"`
26+
CertFile string `env:"CACHE_CERT_FILE_PATH, report"`
27+
KeyFile string `env:"CACHE_KEY_FILE_PATH, report"`
28+
CommonName string `env:"CACHE_COMMON_NAME, report"`
29+
PollingInterval time.Duration `env:"CACHE_POLLING_INTERVAL, report"`
30+
Blacklist blacklist.BlacklistRanges `env:"BLACKLISTED_SYSLOG_RANGES, report"`
3231
}
3332

3433
// Config holds the configuration for the syslog agent
3534
type Config struct {
36-
UseRFC3339 bool `env:"USE_RFC3339"`
37-
BindingsPerAppLimit int `env:"BINDING_PER_APP_LIMIT, report"`
38-
DrainSkipCertVerify bool `env:"DRAIN_SKIP_CERT_VERIFY, report"`
39-
DrainCipherSuites string `env:"DRAIN_CIPHER_SUITES, report"`
40-
DrainTrustedCAFile string `env:"DRAIN_TRUSTED_CA_FILE, report"`
41-
DefaultDrainMetadata bool `env:"DEFAULT_DRAIN_METADATA, report"`
42-
IdleDrainTimeout time.Duration `env:"IDLE_DRAIN_TIMEOUT, report"`
43-
WarnOnInvalidDrains bool `env:"WARN_ON_INVALID_DRAINS, report"`
35+
UseRFC3339 bool `env:"USE_RFC3339"`
36+
BindingsPerAppLimit int `env:"BINDING_PER_APP_LIMIT, report"`
37+
DrainSkipCertVerify bool `env:"DRAIN_SKIP_CERT_VERIFY, report"`
38+
DrainCipherSuites string `env:"DRAIN_CIPHER_SUITES, report"`
39+
DrainTrustedCAFile string `env:"DRAIN_TRUSTED_CA_FILE, report"`
40+
DefaultDrainMetadata bool `env:"DEFAULT_DRAIN_METADATA, report"`
41+
IdleDrainTimeout time.Duration `env:"IDLE_DRAIN_TIMEOUT, report"`
42+
WarnOnInvalidDrains bool `env:"WARN_ON_INVALID_DRAINS, report"`
43+
LoggregatorIngressAddr string `env:"LOGGREGATOR_AGENT_ADDR, report, required"`
4444

4545
GRPC GRPC
4646
Cache Cache

src/cmd/syslog-agent/app/syslog_agent.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
gendiodes "code.cloudfoundry.org/go-diodes"
1414
"code.cloudfoundry.org/go-loggregator/v10"
1515
metrics "code.cloudfoundry.org/go-metric-registry"
16+
"code.cloudfoundry.org/loggregator-agent-release/src/pkg/ingress/applog"
1617
"code.cloudfoundry.org/tlsconfig"
1718

1819
"code.cloudfoundry.org/loggregator-agent-release/src/pkg/binding"
@@ -56,19 +57,14 @@ func NewSyslogAgent(
5657
cfg Config,
5758
m Metrics,
5859
l *log.Logger,
60+
appLogStreamFactory applog.AppLogStreamFactory,
5961
) *SyslogAgent {
6062
internalTlsConfig, externalTlsConfig := drainTLSConfig(cfg)
61-
writerFactory := syslog.NewWriterFactory(
62-
internalTlsConfig,
63-
externalTlsConfig,
64-
syslog.NetworkTimeoutConfig{
65-
Keepalive: 10 * time.Second,
66-
DialTimeout: 10 * time.Second,
67-
WriteTimeout: 10 * time.Second,
68-
},
69-
m,
70-
)
71-
63+
writerFactory := syslog.NewWriterFactory(internalTlsConfig, externalTlsConfig, syslog.NetworkTimeoutConfig{
64+
Keepalive: 10 * time.Second,
65+
DialTimeout: 10 * time.Second,
66+
WriteTimeout: 10 * time.Second,
67+
}, m)
7268
ingressTLSConfig, err := loggregator.NewIngressTLSConfig(
7369
cfg.GRPC.CAFile,
7470
cfg.GRPC.CertFile,
@@ -81,6 +77,7 @@ func NewSyslogAgent(
8177
logClient, err := loggregator.NewIngressClient(
8278
ingressTLSConfig,
8379
loggregator.WithLogger(log.New(os.Stderr, "", log.LstdFlags)),
80+
loggregator.WithAddr(cfg.LoggregatorIngressAddr),
8481
)
8582
if err != nil {
8683
l.Panicf("failed to create log client for syslog connector: %q", err)
@@ -91,7 +88,7 @@ func NewSyslogAgent(
9188
timeoutwaitgroup.New(time.Minute),
9289
writerFactory,
9390
m,
94-
syslog.WithLogClient(logClient, "syslog_agent"),
91+
syslog.WithAppLogStream(appLogStreamFactory.NewAppLogStream(logClient, "syslog_agent")),
9592
)
9693

9794
var cacheClient *cache.CacheClient

src/cmd/syslog-agent/app/syslog_agent_mtls_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"os"
1111
"time"
1212

13+
"code.cloudfoundry.org/loggregator-agent-release/src/pkg/ingress/applog"
14+
1315
. "github.com/onsi/ginkgo/v2"
1416
. "github.com/onsi/gomega"
1517

@@ -154,7 +156,9 @@ var _ = Describe("SyslogAgent with mTLS", func() {
154156
agentCfg.Cache.PollingInterval = 10 * time.Millisecond
155157
}
156158

157-
agent = app.NewSyslogAgent(agentCfg, agentMetrics, agentLogr)
159+
factory := applog.NewAppLogStreamFactory()
160+
161+
agent = app.NewSyslogAgent(agentCfg, agentMetrics, agentLogr, &factory)
158162
go agent.Run()
159163
})
160164

src/cmd/syslog-agent/app/syslog_agent_test.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import (
1313
"strings"
1414
"time"
1515

16+
"code.cloudfoundry.org/loggregator-agent-release/src/pkg/binding/blacklist"
17+
"code.cloudfoundry.org/loggregator-agent-release/src/pkg/ingress/applog"
18+
1619
. "github.com/onsi/ginkgo/v2"
1720
. "github.com/onsi/gomega"
1821

@@ -24,7 +27,6 @@ import (
2427
"code.cloudfoundry.org/loggregator-agent-release/src/internal/testhelper"
2528
"code.cloudfoundry.org/loggregator-agent-release/src/pkg/binding"
2629
"code.cloudfoundry.org/loggregator-agent-release/src/pkg/config"
27-
"code.cloudfoundry.org/loggregator-agent-release/src/pkg/ingress/bindings"
2830
"code.cloudfoundry.org/tlsconfig"
2931
)
3032

@@ -48,6 +50,8 @@ var _ = Describe("SyslogAgent", func() {
4850
agentMetrics *metricsHelpers.SpyMetricsRegistry
4951
agentLogr *log.Logger
5052
agent *app.SyslogAgent
53+
54+
factory applog.AppLogStreamFactory
5155
)
5256

5357
BeforeEach(func() {
@@ -134,7 +138,9 @@ var _ = Describe("SyslogAgent", func() {
134138
agentCfg.Cache.PollingInterval = 10 * time.Millisecond
135139
}
136140

137-
agent = app.NewSyslogAgent(agentCfg, agentMetrics, agentLogr)
141+
factory := applog.NewAppLogStreamFactory()
142+
143+
agent = app.NewSyslogAgent(agentCfg, agentMetrics, agentLogr, &factory)
138144
go agent.Run()
139145
})
140146

@@ -238,6 +244,14 @@ var _ = Describe("SyslogAgent", func() {
238244
Eventually(agentMetrics.GetDebugMetricsEnabled).Should(BeFalse())
239245
})
240246

247+
It("configures appLogStream", func() {
248+
spyFactory := testhelper.SpyAppLogStreamFactory{}
249+
app.NewSyslogAgent(agentCfg, agentMetrics, agentLogr, &spyFactory)
250+
251+
Expect(spyFactory.SourceIndex()).Should(Equal("syslog_agent"))
252+
Expect(spyFactory.LogClient()).ShouldNot(BeNil())
253+
})
254+
241255
Context("when debug configuration is enabled", func() {
242256
BeforeEach(func() {
243257
agentCfg.MetricsServer.DebugMetrics = true
@@ -272,8 +286,8 @@ var _ = Describe("SyslogAgent", func() {
272286
BeforeEach(func() {
273287
url, err := url.Parse(appHTTPSDrain.server.URL)
274288
Expect(err).NotTo(HaveOccurred())
275-
agentCfg.Cache.Blacklist = bindings.BlacklistRanges{
276-
Ranges: []bindings.BlacklistRange{
289+
agentCfg.Cache.Blacklist = blacklist.BlacklistRanges{
290+
Ranges: []blacklist.BlacklistRange{
277291
{
278292
Start: url.Hostname(),
279293
End: url.Hostname(),
@@ -423,7 +437,7 @@ var _ = Describe("SyslogAgent", func() {
423437
cfgCopy.GRPC.KeyFile = "invalid"
424438

425439
msg := `failed to configure client TLS: "failed to load keypair: open invalid: no such file or directory"`
426-
Expect(func() { app.NewSyslogAgent(cfgCopy, agentMetrics, agentLogr) }).To(PanicWith(msg))
440+
Expect(func() { app.NewSyslogAgent(cfgCopy, agentMetrics, agentLogr, factory) }).To(PanicWith(msg))
427441
})
428442
})
429443
})

0 commit comments

Comments
 (0)