mirror of
https://github.com/versity/versitygw.git
synced 2026-08-17 20:56:21 +00:00
Implements the `AssumeRoleWithWebIdentity` and `GetCallerIdentity` STS actions, letting callers exchange an external OIDC token for temporary credentials scoped to an IAM role. Token handling covers JWT claim parsing, issuer/audience resolution (including `azp` override semantics), JWKS fetching and caching with `singleflight`-deduplicated refresh, and rate-limited forced refresh on unrecognized `kid` values. OIDC provider thumbprint fetching now performs a real TLS handshake verified against the system trust store and the provider hostname (previously `InsecureSkipVerify`), since the observed certificate is persisted as a long-lived trust anchor rather than used once and discarded; all discovery-document and JWKS fetches go through an SSRF-safe HTTP client with bounded redirects and response size.
Adds policy `Condition` block evaluation, supporting `String`, `Numeric`, `Date`, `Bool`, `BinaryEquals`, and `IpAddress` operators along with their `IfExists`/`Not` variants and `ForAllValues`/`ForAnyValues` set qualifiers, plus policy variable substitution (e.g. `${aws:username}`) in supported operators. Adds identity-based inline policy evaluation and a new IAM authorization middleware that authorizes each request against action, resource, and condition context together, applying the session-policy-intersects-role-policy semantics for assumed-role sessions.
Adds a new debug logger `--log-level` flag (`silent`/`debug`/`unsafe`), along with a tree-based XML masker that redacts secrets and tokens at the property level in logged request/response bodies instead of skipping the whole body. The old `--debug/VGW_DEBUG` flag is kept as a deprecated alias for `--log-level=debug`, printing a console warning that points users at `--log-level` for finer-grained control.
Fixes a Vault storage bug where CAS (check-and-set) writes always read the current document version as 0 because `kvVersion` asserted metadata as `float64` while the Vault client actually returns `json.Number`, causing every write past the first to be rejected as a concurrent modification. Also adds a constant-time `SecureCompare` for signature/token comparisons in sigv4 auth.
Adds an integration test suite (`iam_access_control.go`) covering IAM access control across user, role, and session identities.
91 lines
2.5 KiB
Go
91 lines
2.5 KiB
Go
// Copyright 2026 Versity Software
|
|
// This file is licensed under the Apache License, Version 2.0
|
|
// (the "License"); you may not use this file except in compliance
|
|
// with the License. You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing,
|
|
// software distributed under the License is distributed on an
|
|
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
// KIND, either express or implied. See the License for the
|
|
// specific language governing permissions and limitations
|
|
// under the License.
|
|
|
|
package debuglogger
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"sync/atomic"
|
|
)
|
|
|
|
// Level controls both whether the debug logger produces any output and,
|
|
// when it does, whether secrets and tokens embedded in that output are
|
|
// masked.
|
|
type Level int32
|
|
|
|
const (
|
|
// LevelSilent prints no debug logs. This is the default.
|
|
LevelSilent Level = iota
|
|
// LevelDebug prints full request/response logs with secrets and
|
|
// tokens (access keys, session tokens, signatures, ...) masked.
|
|
LevelDebug
|
|
// LevelUnsafe prints full request/response logs with secrets and
|
|
// tokens shown in the clear. Anyone with access to this output can
|
|
// read and replay credentials directly; never use in production.
|
|
LevelUnsafe
|
|
)
|
|
|
|
func (l Level) String() string {
|
|
switch l {
|
|
case LevelSilent:
|
|
return "silent"
|
|
case LevelDebug:
|
|
return "debug"
|
|
case LevelUnsafe:
|
|
return "unsafe"
|
|
default:
|
|
return "unknown"
|
|
}
|
|
}
|
|
|
|
// ParseLevel parses "silent", "debug", or "unsafe" (case-insensitive) into
|
|
// a Level. An empty string parses as LevelSilent.
|
|
func ParseLevel(s string) (Level, error) {
|
|
switch strings.ToLower(strings.TrimSpace(s)) {
|
|
case "", "silent":
|
|
return LevelSilent, nil
|
|
case "debug":
|
|
return LevelDebug, nil
|
|
case "unsafe":
|
|
return LevelUnsafe, nil
|
|
default:
|
|
return LevelSilent, fmt.Errorf("invalid log level %q: must be one of 'silent', 'debug', 'unsafe'", s)
|
|
}
|
|
}
|
|
|
|
var currentLevel atomic.Int32
|
|
|
|
// SetLevel sets the active debug log level.
|
|
func SetLevel(l Level) {
|
|
currentLevel.Store(int32(l))
|
|
}
|
|
|
|
// CurrentLevel returns the active debug log level.
|
|
func CurrentLevel() Level {
|
|
return Level(currentLevel.Load())
|
|
}
|
|
|
|
// IsDebugEnabled returns true when the debug logger produces output, at
|
|
// either LevelDebug or LevelUnsafe.
|
|
func IsDebugEnabled() bool {
|
|
return CurrentLevel() != LevelSilent
|
|
}
|
|
|
|
// IsUnsafeEnabled returns true when the debug logger is configured to print
|
|
// secrets and tokens without masking.
|
|
func IsUnsafeEnabled() bool {
|
|
return CurrentLevel() == LevelUnsafe
|
|
}
|