Skip to content

Commit 1a57227

Browse files
authored
feat(kas): add configurable SRT skew tolerance and diagnostics (#2886)
### Proposed Changes * ### Checklist - [ ] I have added or updated unit tests - [ ] I have added or updated integration tests (if appropriate) - [ ] I have added or updated documentation ### Testing Instructions
1 parent 56b0740 commit 1a57227

File tree

10 files changed

+400
-48
lines changed

10 files changed

+400
-48
lines changed

docs/Configuring.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,16 @@ For OTLP provider:
240240
- `trace.provider.otlp.insecure`: Whether to use an insecure connection
241241
- `trace.provider.otlp.headers`: Headers to include in OTLP requests
242242

243+
## Security Configuration
244+
245+
Root level key `security`
246+
247+
| Field | Description | Default |
248+
|-----------------------------|-------------------------------------------------------------------------------------------------|---------|
249+
| `unsafe.clock_skew` | Platform-wide maximum tolerated clock skew for token verification (Go duration, use cautiously) | `1m` |
250+
251+
> **Warning:** Increasing `unsafe.clock_skew` weakens token freshness guarantees. Only raise this value temporarily while you correct clock drift.
252+
243253
## Services Configuration
244254

245255
Root level key `services`
@@ -262,6 +272,11 @@ Environment Variable: `OPENTDF_SERVICES_KAS_KEYRING='[{"kid":"k1","alg":"rsa:204
262272
Example:
263273

264274
```yaml
275+
security:
276+
unsafe:
277+
# Increase only when diagnosing clock drift issues
278+
# clock_skew: 90s
279+
265280
services:
266281
kas:
267282
keyring:

opentdf-kas-mode.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ logger:
1111
level: debug
1212
type: text
1313
output: stdout
14+
security:
15+
unsafe:
16+
# Increase only when diagnosing clock drift issues; default is 1m
17+
# clock_skew: 90s
1418
services:
1519
kas:
1620
registered_kas_uri: http://localhost:8080 # Should match what you have registered for *this* KAS in the policy db.

service/kas/access/provider.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package access
22

33
import (
44
"context"
5+
"log/slog"
56
"net/url"
67
"time"
78

@@ -29,6 +30,7 @@ type Provider struct {
2930
Logger *logger.Logger
3031
Config *config.ServiceConfig
3132
KASConfig
33+
securityConfig *config.SecurityConfig
3234
trace.Tracer
3335
}
3436

@@ -73,6 +75,36 @@ func (p *Provider) IsReady(ctx context.Context) error {
7375
return nil
7476
}
7577

78+
// ApplyConfig stores the latest KAS configuration, tracks the associated security
79+
// overrides, and emits a warning when the configured clock skew exceeds the default.
80+
func (p *Provider) ApplyConfig(cfg KASConfig, securityCfg *config.SecurityConfig) {
81+
p.KASConfig = cfg
82+
p.securityConfig = securityCfg
83+
84+
if p.Logger != nil {
85+
if skew := p.acceptableSkew(); skew > config.DefaultUnsafeClockSkew {
86+
p.Logger.Warn("configured SRT acceptable skew exceeds default",
87+
slog.Duration("configured_skew", skew),
88+
slog.Duration("default_skew", config.DefaultUnsafeClockSkew),
89+
)
90+
}
91+
}
92+
}
93+
94+
// SecurityConfig exposes the most recent security configuration captured via ApplyConfig.
95+
func (p *Provider) SecurityConfig() *config.SecurityConfig {
96+
return p.securityConfig
97+
}
98+
99+
// acceptableSkew returns the tolerated clock skew for SRT validation, falling back to the
100+
// global unsafe default when no override is present.
101+
func (p *Provider) acceptableSkew() time.Duration {
102+
if p.securityConfig == nil {
103+
return config.DefaultUnsafeClockSkew
104+
}
105+
return p.securityConfig.ClockSkew()
106+
}
107+
76108
func (kasCfg *KASConfig) UpgradeMapToKeyring(c *security.StandardCrypto) {
77109
switch {
78110
case kasCfg.ECCertID != "" && len(kasCfg.Keyring) > 0:

0 commit comments

Comments
 (0)