Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

authz: Rbac engine audit logging #6225

Merged
merged 106 commits into from May 17, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
8b9f59a
Add conversion of json to RBAC Audit Logging config
gtcooke94 Apr 6, 2023
56ab1cd
Swap to passing around references instead of copied values
gtcooke94 Apr 14, 2023
0f3b6e7
Change v3 to v3corepb
gtcooke94 Apr 14, 2023
6bff58b
go mod tidy compat=1.17
gtcooke94 Apr 14, 2023
9b3ab47
go mod tidy in examples
gtcooke94 Apr 14, 2023
bbafb89
mod tidy
gtcooke94 Apr 14, 2023
5dad66e
go mod tidy compat=1.17
gtcooke94 Apr 14, 2023
73b1390
more tidy
gtcooke94 Apr 14, 2023
27cfe85
replace panic with t.fatal
gtcooke94 Apr 17, 2023
c8751d3
return nil when error
gtcooke94 Apr 17, 2023
441fb5c
lowercase start of error message
gtcooke94 Apr 17, 2023
2326e9f
remove redundant change
gtcooke94 Apr 17, 2023
abcb93f
Fix test logging hard-coding problem
gtcooke94 Apr 17, 2023
3f57e69
Changed behavior of missing configs per PR discussion
gtcooke94 Apr 18, 2023
b7863ee
Change parser to use map from generated proto go file
gtcooke94 Apr 18, 2023
48a875e
ALLOW and DENY filter should get separate audit logger config
gtcooke94 Apr 18, 2023
edf40f1
Small change remove and else
gtcooke94 Apr 18, 2023
551ced9
Construct and allow and denyproto from the beginning
gtcooke94 Apr 19, 2023
1718c45
Merge branch 'master' into AuditLoggingRBACTranslator
gtcooke94 Apr 19, 2023
dad7293
compat 1.17 in examples
gtcooke94 Apr 19, 2023
7b9e96e
more 1.17 compat
gtcooke94 Apr 19, 2023
1f4c0c0
Address PR comments
gtcooke94 Apr 20, 2023
2eb4512
starting work
gtcooke94 Apr 20, 2023
fd97b2c
Move audit logger to it's own package
gtcooke94 Apr 20, 2023
ca8f66c
remove audit prefixes since its the package name now
gtcooke94 Apr 21, 2023
bf571d6
Add package comment
gtcooke94 Apr 21, 2023
49f1ff3
Merge branch 'MoveAuditPackage' into RBACEngine
gtcooke94 Apr 21, 2023
066adbb
Merge branch 'master' into RBACEngine
gtcooke94 Apr 21, 2023
472d752
some work
gtcooke94 Apr 21, 2023
66fa61a
Shell for audit logging
gtcooke94 Apr 21, 2023
95a5253
Continuing impl
gtcooke94 Apr 21, 2023
67a71ff
Continuing work
gtcooke94 Apr 25, 2023
1a4e978
Adding NewChainEngine tests
gtcooke94 Apr 25, 2023
1a5b03d
Don't create a new anonymous type every time
gtcooke94 Apr 26, 2023
5490046
basic engine test
gtcooke94 Apr 26, 2023
1c4b097
Working on pushing policyname through
gtcooke94 Apr 26, 2023
0747d62
Changing NewChainEngine to include policyName
gtcooke94 Apr 26, 2023
fa5e894
new commented tests
gtcooke94 Apr 26, 2023
b95b6f1
Renamed to NewChainEngine
gtcooke94 Apr 26, 2023
9ef033b
Finish renaming
gtcooke94 Apr 26, 2023
4896f7e
More tests
gtcooke94 Apr 26, 2023
6fb2f46
more tests
gtcooke94 Apr 26, 2023
760f946
More comments
gtcooke94 Apr 26, 2023
d426edb
Add policyName to tests
gtcooke94 Apr 26, 2023
5aef84f
merge master
gtcooke94 Apr 26, 2023
1b60ec1
fix
gtcooke94 Apr 26, 2023
6287772
Cleanup
gtcooke94 Apr 26, 2023
90a1306
tests for bad cases
gtcooke94 Apr 26, 2023
bc236d9
configJson -> configJSON
gtcooke94 Apr 26, 2023
60338b3
Added feature and tests for handling IsOptional on unsupported logger…
gtcooke94 Apr 26, 2023
c4e6067
Make lines wrap shorter
gtcooke94 Apr 27, 2023
4fec2a8
Addressing PR comments
gtcooke94 Apr 27, 2023
60088e3
Addressing PR comments
gtcooke94 Apr 27, 2023
50f2673
undo rename of matchingPolicyName
gtcooke94 Apr 27, 2023
26e48ce
make builder manage the list of auditEvents
gtcooke94 Apr 27, 2023
67613d3
Add comment in internal.go
gtcooke94 Apr 27, 2023
468126a
Don't use pointer to audit.Logger interface
gtcooke94 Apr 27, 2023
4a9e3f8
Change error message
gtcooke94 Apr 27, 2023
16ea27e
Cleanup parsing custom config
gtcooke94 Apr 27, 2023
89bc833
changing a name for receiver consistency
gtcooke94 Apr 27, 2023
938b6b9
rename engine receiver -> e
gtcooke94 Apr 28, 2023
752d9e6
Refactor audit logger option parsing to it's own func
gtcooke94 Apr 28, 2023
844216c
Change to more preferred slice declaration
gtcooke94 Apr 28, 2023
a46cd2e
Merge branch 'master' into RBACEngineAuditLogging
gtcooke94 May 1, 2023
f86c660
Moving to correct TypedConfig structure for custom config
gtcooke94 May 1, 2023
cab68ba
Use TypedStruct properly for custom configs
gtcooke94 May 2, 2023
21a3788
parse out the prefix of the name
gtcooke94 May 2, 2023
5e5f9e9
Move custom config logic to it's own converter.go file, setup pattern…
gtcooke94 May 2, 2023
724e066
standardize imports
gtcooke94 May 2, 2023
89aca52
Change principal handling:
gtcooke94 May 2, 2023
1685b62
Remove extra package comment
gtcooke94 May 3, 2023
2f51981
Rename helper functions
gtcooke94 May 3, 2023
8e20f7f
fix go vet error
gtcooke94 May 3, 2023
c5798a9
Added error cases for buildLogger
gtcooke94 May 3, 2023
d35a865
Actually add the new converter_test.go file
gtcooke94 May 3, 2023
9e16b15
Remove tests that weren't being used
gtcooke94 May 4, 2023
697ad75
Add copyright
gtcooke94 May 4, 2023
2bead31
git messiness, sorry
gtcooke94 May 4, 2023
5ce64e9
combine if conditions
gtcooke94 May 4, 2023
1402f64
Addressing PR comments
gtcooke94 May 4, 2023
ac17f03
Address PR comments
gtcooke94 May 5, 2023
488c09d
Use test name for individual loggers rather than clearing the registry
gtcooke94 May 9, 2023
9fa7542
Remove internal unregister function
gtcooke94 May 9, 2023
5392f60
remove unregisterLoggerBuilder
gtcooke94 May 9, 2023
421acff
Apply punctuation suggestions from code review
gtcooke94 May 9, 2023
0960c8b
%s/typedURLPrefix/typeURLPrefix
gtcooke94 May 9, 2023
2cb5de1
More PR comments
gtcooke94 May 9, 2023
361dcba
Merge master
gtcooke94 May 9, 2023
4dd9061
Add more descriptive error in helper
gtcooke94 May 9, 2023
a81070c
Own TODO
gtcooke94 May 9, 2023
50d1699
Apply suggestions from code review
gtcooke94 May 10, 2023
1637d73
Address PR comments
gtcooke94 May 15, 2023
4c2b1bb
Change how we get SPIFFE ID
gtcooke94 May 16, 2023
218ba4b
Change missing custom config behavior
gtcooke94 May 16, 2023
1ec90ed
Merge remote-tracking branch 'origin/RBACEngineAuditLogging' into RBA…
gtcooke94 May 16, 2023
85696a7
lowercase
gtcooke94 May 16, 2023
d8777da
Change error message
gtcooke94 May 16, 2023
cfaf71d
reword other errors
gtcooke94 May 16, 2023
dd6ff8d
Fix test error strings
gtcooke94 May 16, 2023
4362f75
handle s == nil
gtcooke94 May 16, 2023
d582f2c
use value instead of pointer
gtcooke94 May 16, 2023
6908c86
Remove unnecessary spiffe scheme check
gtcooke94 May 16, 2023
ea8f50e
Make for loop use value
gtcooke94 May 16, 2023
dd2f2a6
Swap to []*auditLogger
gtcooke94 May 16, 2023
52f77b8
Add check for empty audit logger name
gtcooke94 May 16, 2023
2f0a376
Better error message
gtcooke94 May 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 0 additions & 12 deletions authz/audit/audit_logger.go
Expand Up @@ -22,8 +22,6 @@ package audit
import (
"encoding/json"
"sync"

"google.golang.org/grpc/internal"
)

// loggerBuilderRegistry holds a map of audit logger builders and a mutex
Expand All @@ -39,10 +37,6 @@ var (
}
)

func init() {
internal.UnregisterAuditLoggerBuilderForTesting = unregisterLoggerBuilder
}

// RegisterLoggerBuilder registers the builder in a global map
// using b.Name() as the key.
//
Expand All @@ -63,12 +57,6 @@ func GetLoggerBuilder(name string) LoggerBuilder {
return registry.builders[name]
}

func unregisterLoggerBuilder(name string) {
registry.mu.Lock()
defer registry.mu.Unlock()
delete(registry.builders, name)
}

// Event contains information passed to the audit logger as part of an
// audit logging event.
type Event struct {
Expand Down
8 changes: 4 additions & 4 deletions authz/rbac_translator.go
Expand Up @@ -39,7 +39,7 @@ import (

// This is used when converting a custom config from raw JSON to a TypedStruct
// The TypeURL of the TypeStruct will be "grpc.authz.audit_logging/<name>"
const typedURLPrefix = "grpc.authz.audit_logging/"
const typeURLPrefix = "grpc.authz.audit_logging/"

type header struct {
Key string
Expand Down Expand Up @@ -308,7 +308,7 @@ func (options *auditLoggingOptions) toProtos() (allow *v3rbacpb.RBAC_AuditLoggin
return nil, nil, fmt.Errorf("AuditLogger Config field cannot be nil")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, empty audit logger config is a valid thing but it means that Audit is disabled

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might've changed, but I believe last we discussed that custom config on the individual Audit Logger needed to be an empty JSON object?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If nil means config field is missing from the given json, then it will be fine. We want the config to be a valid json object only if it's present.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed, PTAL

}
typedStruct := &v1xdsudpatypepb.TypedStruct{
TypeUrl: typedURLPrefix + config.Name,
TypeUrl: typeURLPrefix + config.Name,
rockspore marked this conversation as resolved.
Show resolved Hide resolved
Value: config.Config,
}
customConfig, err := anypb.New(typedStruct)
Expand Down Expand Up @@ -355,8 +355,8 @@ func toDenyCondition(condition v3rbacpb.RBAC_AuditLoggingOptions_AuditCondition)

// translatePolicy translates SDK authorization policy in JSON format to two
// Envoy RBAC polices (deny followed by allow policy) or only one Envoy RBAC
// allow policy. If the input policy cannot be parsed or is invalid, an error
// will be returned.
// allow policy. Also returns the overall policy name. If the input policy
// cannot be parsed or is invalid, an error will be returned.
func translatePolicy(policyStr string) ([]*v3rbacpb.RBAC, string, error) {
gtcooke94 marked this conversation as resolved.
Show resolved Hide resolved
policy := &authorizationPolicy{}
d := json.NewDecoder(bytes.NewReader([]byte(policyStr)))
Expand Down
2 changes: 1 addition & 1 deletion authz/rbac_translator_test.go
Expand Up @@ -951,7 +951,7 @@ func anyPbHelper(t *testing.T, in map[string]interface{}, name string) *anypb.An
t.Helper()
pb, err := structpb.NewStruct(in)
typedStruct := &v1xdsudpatypepb.TypedStruct{
TypeUrl: typedURLPrefix + name,
TypeUrl: typeURLPrefix + name,
Value: pb,
}
if err != nil {
Expand Down
6 changes: 0 additions & 6 deletions internal/internal.go
Expand Up @@ -164,12 +164,6 @@ var (

// ORCAAllowAnyMinReportingInterval is for examples/orca use ONLY.
ORCAAllowAnyMinReportingInterval interface{} // func(so *orca.ServiceOptions)

// UnregisterAuditLoggerBuilderForTesting unregisters the AuditLoggerBuilder
// by name for testing purposes. This is needed because there is no way to
// unregister for repeated tests. It is set by package authz/audit in
// audit_logger.go
UnregisterAuditLoggerBuilderForTesting func(name string)
)

// HealthChecker defines the signature of the client-side LB channel health checking function.
Expand Down
8 changes: 3 additions & 5 deletions internal/xds/rbac/converter_test.go
Expand Up @@ -23,7 +23,6 @@ import (
v3corepb "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
v3rbacpb "github.com/envoyproxy/go-control-plane/envoy/config/rbac/v3"
"google.golang.org/grpc/authz/audit"
"google.golang.org/grpc/internal"
"google.golang.org/protobuf/types/known/anypb"
)

Expand Down Expand Up @@ -79,7 +78,7 @@ func (s) TestBuildLoggerErrors(t *testing.T) {
loggerConfig: &v3rbacpb.RBAC_AuditLoggingOptions_AuditLoggerConfig{
AuditLogger: &v3corepb.TypedExtensionConfig{
Name: "TestAuditLoggerCustomConfig",
TypedConfig: createUDPATypedStruct(t, map[string]interface{}{"abc": "BADVALUE", "xyz": "123"}, "TestAuditLoggerCustomConfig")},
TypedConfig: createUDPATypedStruct(t, map[string]interface{}{"abc": "BADVALUE", "xyz": "123"}, "fail to parse custom config_TestAuditLoggerCustomConfig")},
IsOptional: false,
},
expectedError: "AuditLogger custom config could not be parsed",
Expand All @@ -89,7 +88,7 @@ func (s) TestBuildLoggerErrors(t *testing.T) {
loggerConfig: &v3rbacpb.RBAC_AuditLoggingOptions_AuditLoggerConfig{
AuditLogger: &v3corepb.TypedExtensionConfig{
Name: "UnregisteredLogger",
TypedConfig: createUDPATypedStruct(t, map[string]interface{}{}, "UnregisteredLogger"),
TypedConfig: createUDPATypedStruct(t, map[string]interface{}{}, "No registered logger but optional passes_UnregisteredLogger"),
gtcooke94 marked this conversation as resolved.
Show resolved Hide resolved
},
IsOptional: true,
},
Expand All @@ -98,9 +97,8 @@ func (s) TestBuildLoggerErrors(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
b := TestAuditLoggerCustomConfigBuilder{}
b := TestAuditLoggerCustomConfigBuilder{testName: test.name}
audit.RegisterLoggerBuilder(&b)
defer internal.UnregisterAuditLoggerBuilderForTesting(b.Name())
logger, err := buildLogger(test.loggerConfig)
if err != nil && !strings.HasPrefix(err.Error(), test.expectedError) {
t.Fatalf("expected error: %v. got error: %v", test.expectedError, err)
Expand Down
12 changes: 7 additions & 5 deletions internal/xds/rbac/rbac_engine.go
Expand Up @@ -122,7 +122,7 @@ type engine struct {
auditCondition v3rbacpb.RBAC_AuditLoggingOptions_AuditCondition
}

// newEngine creates an RBAC Engine based on the contents of policy. Returns a
// newEngine creates an RBAC Engine based on the contents of a policy. Returns a
// non-nil error if the policy is invalid.
func newEngine(config *v3rbacpb.RBAC, policyName string) (*engine, error) {
a := config.GetAction()
Expand All @@ -144,11 +144,11 @@ func newEngine(config *v3rbacpb.RBAC, policyName string) (*engine, error) {
return nil, err
}
return &engine{
policyName: policyName,
policies: policies,
action: a,
auditLoggers: auditLoggers,
auditCondition: auditCondition,
policyName: policyName,
}, nil
}

Expand All @@ -163,6 +163,8 @@ func parseAuditOptions(opts *v3rbacpb.RBAC_AuditLoggingOptions) ([]audit.Logger,
return nil, v3rbacpb.RBAC_AuditLoggingOptions_NONE, err
}
if auditLogger == nil {
// This occurs when the audit logger is not registered but also
// marked optional.
continue
}
auditLoggers = append(auditLoggers, auditLogger)
Expand Down Expand Up @@ -304,6 +306,6 @@ func (e *engine) doAuditLogging(rpcData *rpcData, rule string, authorized bool)
}
}

// This is used when converting a custom config from raw JSON to a TypedStruct
// The TypeURL of the TypeStruct will be "grpc.authz.audit_logging/<name>"
const typedURLPrefix = "grpc.authz.audit_logging/"
// This is used when converting a custom config from raw JSON to a TypedStruct.
// The TypeURL of the TypeStruct will be "grpc.authz.audit_logging/<name>".
const typeURLPrefix = "grpc.authz.audit_logging/"