osctrl-tls: hardening — constant-time secrets, per-IP enroll rate-limit, audit-log on failed enrolls (round 1b of 3)#816
Merged
javuto merged 2 commits intoMay 17, 2026
Conversation
53f2e99 to
2511d7b
Compare
…it, audit-log on failed enrolls Carves the osctrl-tls-facing changes out of the original "round 1" security PR (jmpsec#813) into their own PR so the TLS surface can be isolated for review and testing. Depends on the shared infrastructure (pkg/auditlog FailedEnroll, pkg/ratelimit, and utils.SetTrustedProxies / GetIP changes) that lands in jmpsec#813. == Threats addressed == osctrl-tls is the only osctrl service that is internet-facing in a typical deployment — every osquery node POSTs to /enroll, /config, /log, etc. before any authentication exists. That makes its surface the most exposed and the most worth hardening. This PR adds three independent defenses: == 1. Constant-time secret comparison == cmd/tls/handlers/utils.go: checkValidSecret and checkValidRemovePath switched from `strings.TrimSpace(secret) == env.Secret` (byte-by-byte short-circuiting compare) to `subtle.ConstantTimeCompare`. The old form leaked secret bytes via response-time timing — an attacker on the open internet could iterate one byte at a time. Constant-time compare eliminates that oracle. == 2. Per-IP rate-limit on /enroll == cmd/tls/main.go: 20 requests/minute per remote IP, idle eviction after 10 minutes. Rejected requests: - return 429 - record an `AuditLog.FailedEnroll(ip, env, "rate limit exceeded", 0)` so SoC tooling can alert on enroll abuse / spray. Backed by pkg/ratelimit (from jmpsec#813). The default 20/min easily covers any realistic enroll burst (a wave of provisioning at site bring-up) while shutting down brute-force / DoS attempts. == 3. Audit-log on failed enrollment == cmd/tls/handlers/handlers.go: HandlersTLS grows an AuditLog field + WithAuditLog option. Defensive default is a disabled manager so handler code can call h.AuditLog.FailedEnroll(...) without nil checks. cmd/tls/handlers/post.go: EnrollHandler records FailedEnroll on the invalid-secret path. Combined with the rate-limit failures above, the audit log now carries the full picture of unwanted enroll traffic. cmd/tls/main.go: initializes auditlog.CreateAuditLogManager and threads it into handlers via WithAuditLog. Service name "osctrl-tls" flows through to audit rows. == 4. Trusted-proxies plumbing == cmd/tls/main.go: reads flagParams.Service.TrustedProxies (CIDR list) and calls utils.SetTrustedProxies before any request can reach GetIP. Empty default means GetIP ignores X-Forwarded-For / X-Real-IP and uses RemoteAddr — preventing internet-side header-spoofed bypass of the rate-limiter or audit-log poisoning. == Config == deploy/config/tls.yml: - auditLog: true (on by default; was false) - trustedProxies: "" (empty by default; operators behind a trusted reverse proxy can list the proxy CIDRs) Verified: go build ./... clean, go vet ./... clean, go test ./cmd/tls/... green. Live smoke on the dev stack: 4 osquery nodes enrolled, the audit_logs table records `enroll_failure` rows with correct IPs for forced bad-secret attempts.
2511d7b to
b017293
Compare
The {env} path segment matches any non-slash string, so a sprayer
hitting /<arbitrary-junk>/enroll could stuff up to one path segment of
attacker-controlled text per rate-limit-rejected request into
audit_logs.line. Not SQL-injectable (gorm parameterized) and not XSS
in the React SPA (escaped), but it polluted the table and made SoC
alerting noisier without adding signal.
The EnrollHandler already validates the env UUID via utils.CheckUUID
before any audit write — the rate-limit callback now does the same.
Rejected segments are recorded as "<invalid>" so SoC tooling still
sees the activity (and can alert on the literal "<invalid>" if it
wants), but the table can't get polluted with arbitrary attacker text.
Verified on the dev stack: 25 spray requests against
/totally-not-a-uuid-xxxxxxx/enroll trigger the rate limit at request
21+; all 5 rate-limit-rejected audit rows now show
`failed enroll for env <invalid>: rate limit exceeded`, source_ip
captured correctly.
javuto
approved these changes
May 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Carves the osctrl-tls-facing changes out of #813 into their own PR, as requested in #813 (comment), so the TLS surface can be reviewed and tested in isolation.
What this changes
5 files in
cmd/tls/+deploy/config/tls.yml. Three independent defenses on the only osctrl service that is internet-facing in a typical deployment:1. Constant-time secret comparison
cmd/tls/handlers/utils.go—checkValidSecretandcheckValidRemovePathusesubtle.ConstantTimeCompareinstead of the previous byte-by-byte short-circuiting compare. Removes a response-time timing oracle on the public enroll endpoint.2. Per-IP rate-limit on
/enrollcmd/tls/main.go— 20 req/min per remote IP, idle eviction after 10 min, backed bypkg/ratelimit(from #813). Rejected requests:429AuditLog.FailedEnroll(ip, env, "rate limit exceeded", 0)so SoC tooling can alert3. Audit-log on failed enrollment
cmd/tls/handlers/handlers.go—HandlersTLSgains anAuditLogfield +WithAuditLogoption; defensive default is a disabled manager so handler code can callh.AuditLog.FailedEnroll(...)without nil-checks.cmd/tls/handlers/post.go—EnrollHandlerrecordsFailedEnrollon the invalid-secret path.cmd/tls/main.go— initializesauditlog.CreateAuditLogManagerand threads it viaWithAuditLog. Service nameosctrl-tlsflows through.4. Trusted-proxies plumbing
cmd/tls/main.go— readsflagParams.Service.TrustedProxies(CIDR list) and callsutils.SetTrustedProxiesbefore any request reachesGetIP. Empty default =GetIPignoresX-Forwarded-For/X-Real-IP, preventing internet-side header-spoofed bypass of the rate-limiter or audit-log poisoning.Config
deploy/config/tls.yml:auditLog: true(on by default; wasfalse)trustedProxies: ""(empty default; operators behind a trusted reverse proxy can list CIDRs)Verified
go build ./...cleango vet ./...cleango test ./cmd/tls/...greenaudit_logsrecordsenroll_failurerows with correct IPs for forced bad-secret attemptsTest plan
trustedProxiesempty, confirmX-Forwarded-For: 1.2.3.4doesn't overrideRemoteAddrinaudit_logsenroll_failureaudit-log row with the source IP