feat(authmethods): Add classification to all fields
This commit is contained in:
1 parent
2ade7f34a8
commit
8c452b0991
7 files changed
+221
-90
No files matched your search
@@ -69,13 +69,11 @@ func TestCrud(t *testing.T) {
|
||||
reqItem := tests_api.GetEventDetails(t, got, "request")["item"].(map[string]interface{})
|
||||
tests_api.AssertRedactedValues(t, reqItem)
|
||||
tests_api.AssertRedactedValues(t, reqItem["Attrs"])
|
||||
// TODO(johanbrandhorst): Not all of these fields will be redacted eventually
|
||||
tests_api.AssertRedactedValues(t, reqItem["Attrs"].(map[string]interface{})["PasswordAuthMethodAttributes"])
|
||||
|
||||
respItem := tests_api.GetEventDetails(t, got, "response")["item"].(map[string]interface{})
|
||||
tests_api.AssertRedactedValues(t, respItem)
|
||||
tests_api.AssertRedactedValues(t, respItem["Attrs"])
|
||||
// TODO(johanbrandhorst): Not all of these fields will be redacted eventually
|
||||
tests_api.AssertRedactedValues(t, respItem["Attrs"].(map[string]interface{})["PasswordAuthMethodAttributes"])
|
||||
|
||||
_ = os.WriteFile(eventConfig.AuditEvents.Name(), nil, 0o666) // clean out audit events from previous calls
|
||||
@@ -89,7 +87,6 @@ func TestCrud(t *testing.T) {
|
||||
respItem = tests_api.GetEventDetails(t, got, "response")["item"].(map[string]interface{})
|
||||
tests_api.AssertRedactedValues(t, respItem)
|
||||
tests_api.AssertRedactedValues(t, respItem["Attrs"])
|
||||
// TODO(johanbrandhorst): Not all of these fields will be redacted eventually
|
||||
tests_api.AssertRedactedValues(t, respItem["Attrs"].(map[string]interface{})["PasswordAuthMethodAttributes"])
|
||||
|
||||
_ = os.WriteFile(eventConfig.AuditEvents.Name(), nil, 0o666) // clean out audit events from previous calls
|
||||
@@ -103,7 +100,6 @@ func TestCrud(t *testing.T) {
|
||||
respItem = tests_api.GetEventDetails(t, got, "response")["item"].(map[string]interface{})
|
||||
tests_api.AssertRedactedValues(t, respItem)
|
||||
tests_api.AssertRedactedValues(t, respItem["Attrs"])
|
||||
// TODO(johanbrandhorst): Not all of these fields will be redacted eventually
|
||||
tests_api.AssertRedactedValues(t, respItem["Attrs"].(map[string]interface{})["PasswordAuthMethodAttributes"])
|
||||
|
||||
pw, err = amClient.Update(tc.Context(), pw.Item.Id, pw.Item.Version, authmethods.DefaultName())
|
||||
@@ -129,14 +125,12 @@ func TestCrud(t *testing.T) {
|
||||
reqItem = tests_api.GetEventDetails(t, got, "request")["item"].(map[string]interface{})
|
||||
tests_api.AssertRedactedValues(t, reqItem)
|
||||
tests_api.AssertRedactedValues(t, reqItem["Attrs"])
|
||||
// TODO(johanbrandhorst): Not all of these fields will be redacted eventually
|
||||
tests_api.AssertRedactedValues(t, reqItem["Attrs"].(map[string]interface{})["OidcAuthMethodsAttributes"], "callback_url", "state", "client_secret_hmac")
|
||||
tests_api.AssertRedactedValues(t, reqItem["Attrs"].(map[string]interface{})["OidcAuthMethodsAttributes"])
|
||||
|
||||
respItem = tests_api.GetEventDetails(t, got, "response")["item"].(map[string]interface{})
|
||||
tests_api.AssertRedactedValues(t, respItem)
|
||||
tests_api.AssertRedactedValues(t, respItem["Attrs"])
|
||||
// TODO(johanbrandhorst): Not all of these fields will be redacted eventually
|
||||
tests_api.AssertRedactedValues(t, respItem["Attrs"].(map[string]interface{})["OidcAuthMethodsAttributes"], "state", "client_secret_hmac", "callback_url")
|
||||
tests_api.AssertRedactedValues(t, respItem["Attrs"].(map[string]interface{})["OidcAuthMethodsAttributes"])
|
||||
|
||||
oidc, err = amClient.Read(tc.Context(), oidc.Item.Id)
|
||||
require.NoError(err)
|
||||
@@ -300,13 +294,11 @@ func TestCustomMethods(t *testing.T) {
|
||||
reqDetails := tests_api.GetEventDetails(t, got, "request")
|
||||
tests_api.AssertRedactedValues(t, reqDetails)
|
||||
tests_api.AssertRedactedValues(t, reqDetails["Attrs"])
|
||||
// TODO(johanbrandhorst): Not all of these fields will be redacted eventually
|
||||
tests_api.AssertRedactedValues(t, reqDetails["Attrs"].(map[string]interface{})["OidcChangeStateAttributes"], "state")
|
||||
tests_api.AssertRedactedValues(t, reqDetails["Attrs"].(map[string]interface{})["OidcChangeStateAttributes"])
|
||||
|
||||
respItem := tests_api.GetEventDetails(t, got, "response")["item"].(map[string]interface{})
|
||||
tests_api.AssertRedactedValues(t, respItem)
|
||||
// TODO(johanbrandhorst): Not all of these fields will be redacted eventually
|
||||
tests_api.AssertRedactedValues(t, respItem["Attrs"].(map[string]interface{})["OidcAuthMethodsAttributes"], "signing_algorithms", "callback_url", "idp_ca_certs", "state", "client_secret_hmac")
|
||||
tests_api.AssertRedactedValues(t, respItem["Attrs"].(map[string]interface{})["OidcAuthMethodsAttributes"])
|
||||
|
||||
_, err = amClient.ChangeState(tc.Context(), u.Item.Id, u.Item.Version, "", authmethods.WithOidcAuthMethodDisableDiscoveredConfigValidation(true))
|
||||
assert.Error(err)
|
||||
|
||||
@@ -22,6 +22,10 @@ func TestAuthMethod_Tags(t *testing.T) {
|
||||
now := time.Now()
|
||||
wrapper := wrapper.TestWrapper(t)
|
||||
testEncryptingFilter := api.NewEncryptFilter(t, wrapper)
|
||||
testEncryptingFilter.FilterOperationOverrides = map[encrypt.DataClassification]encrypt.FilterOperation{
|
||||
// Use HMAC for sensitive fields for easy test comparisons
|
||||
encrypt.SensitiveClassification: encrypt.HmacSha256Operation,
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -78,21 +82,20 @@ func TestAuthMethod_Tags(t *testing.T) {
|
||||
Name: &wrapperspb.StringValue{Value: "name"},
|
||||
Description: &wrapperspb.StringValue{Value: "description"},
|
||||
Type: "oidc",
|
||||
// TODO(johanbrandhorst): update redaction once typed attributes are available
|
||||
Attrs: &pb.AuthMethod_OidcAuthMethodsAttributes{
|
||||
OidcAuthMethodsAttributes: &pb.OidcAuthMethodAttributes{
|
||||
State: encrypt.RedactedData,
|
||||
Issuer: wrapperspb.String(encrypt.RedactedData),
|
||||
ClientId: wrapperspb.String(encrypt.RedactedData),
|
||||
ClientSecretHmac: encrypt.RedactedData,
|
||||
State: "public-state",
|
||||
Issuer: wrapperspb.String("public-issuer"),
|
||||
ClientId: wrapperspb.String("public-client_id"),
|
||||
ClientSecretHmac: "public-client_secret_hmac",
|
||||
MaxAge: wrapperspb.UInt32(100),
|
||||
SigningAlgorithms: []string{encrypt.RedactedData},
|
||||
IdpCaCerts: []string{encrypt.RedactedData},
|
||||
ApiUrlPrefix: wrapperspb.String(encrypt.RedactedData),
|
||||
CallbackUrl: encrypt.RedactedData,
|
||||
AllowedAudiences: []string{encrypt.RedactedData},
|
||||
ClaimsScopes: []string{encrypt.RedactedData},
|
||||
AccountClaimMaps: []string{encrypt.RedactedData},
|
||||
SigningAlgorithms: []string{"public-signing_algorithms"},
|
||||
IdpCaCerts: []string{"public-idp_ca_certs"},
|
||||
ApiUrlPrefix: wrapperspb.String("public-api_url_prefix"),
|
||||
CallbackUrl: "public-callback_url",
|
||||
AllowedAudiences: []string{"public-allowed_audiences"},
|
||||
ClaimsScopes: []string{"public-claims_scopes"},
|
||||
AccountClaimMaps: []string{"public-account_claim_maps"},
|
||||
DisableDiscoveredConfigValidation: false,
|
||||
DryRun: false,
|
||||
ClientSecret: wrapperspb.String(encrypt.RedactedData),
|
||||
@@ -147,7 +150,6 @@ func TestAuthMethod_Tags(t *testing.T) {
|
||||
Name: &wrapperspb.StringValue{Value: "name"},
|
||||
Description: &wrapperspb.StringValue{Value: "description"},
|
||||
Type: "password",
|
||||
// TODO(johanbrandhorst): update redaction once typed attributes are available
|
||||
Attrs: &pb.AuthMethod_PasswordAuthMethodAttributes{
|
||||
PasswordAuthMethodAttributes: &pb.PasswordAuthMethodAttributes{
|
||||
MinLoginNameLength: 100,
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/hashicorp/eventlogger/filters/encrypt"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/protobuf/types/known/structpb"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
)
|
||||
|
||||
@@ -28,6 +29,10 @@ func TestAuthenticate_Tags(t *testing.T) {
|
||||
now := time.Now()
|
||||
wrapper := wrapper.TestWrapper(t)
|
||||
testEncryptingFilter := api.NewEncryptFilter(t, wrapper)
|
||||
testEncryptingFilter.FilterOperationOverrides = map[encrypt.DataClassification]encrypt.FilterOperation{
|
||||
// Use HMAC for sensitive fields for easy test comparisons
|
||||
encrypt.SensitiveClassification: encrypt.HmacSha256Operation,
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -35,7 +40,48 @@ func TestAuthenticate_Tags(t *testing.T) {
|
||||
wantEvent *eventlogger.Event
|
||||
}{
|
||||
{
|
||||
name: "validate-response-filtering",
|
||||
name: "validate-authenticate-request-filtering",
|
||||
testEvent: &eventlogger.Event{
|
||||
Type: "test",
|
||||
CreatedAt: now,
|
||||
Payload: &services.AuthenticateRequest{
|
||||
AuthMethodId: "public-auth-method-id",
|
||||
TokenType: "public-token-type",
|
||||
Command: "public-command",
|
||||
Attrs: &services.AuthenticateRequest_OidcStartAttributes{
|
||||
OidcStartAttributes: &services.OidcStartAttributes{
|
||||
RoundtripPayload: &structpb.Struct{
|
||||
Fields: map[string]*structpb.Value{
|
||||
"key": structpb.NewStringValue("value"),
|
||||
},
|
||||
},
|
||||
CachedRoundtripPayload: "public-cached_roundtrip_payload",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantEvent: &eventlogger.Event{
|
||||
Type: "test",
|
||||
CreatedAt: now,
|
||||
Payload: &services.AuthenticateRequest{
|
||||
AuthMethodId: "public-auth-method-id",
|
||||
TokenType: "public-token-type",
|
||||
Command: "public-command",
|
||||
Attrs: &services.AuthenticateRequest_OidcStartAttributes{
|
||||
OidcStartAttributes: &services.OidcStartAttributes{
|
||||
RoundtripPayload: &structpb.Struct{
|
||||
Fields: map[string]*structpb.Value{
|
||||
"key": structpb.NewStringValue(encrypt.RedactedData),
|
||||
},
|
||||
},
|
||||
CachedRoundtripPayload: encrypt.TestHmacSha256(t, []byte("public-cached_roundtrip_payload"), wrapper, nil, nil),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "validate-authenticate-response-filtering",
|
||||
testEvent: &eventlogger.Event{
|
||||
Type: "test",
|
||||
CreatedAt: now,
|
||||
@@ -73,7 +119,6 @@ func TestAuthenticate_Tags(t *testing.T) {
|
||||
CreatedAt: now,
|
||||
Payload: &services.AuthenticateResponse{
|
||||
Command: "public-command",
|
||||
// TODO(johanbrandhorst): update redaction once typed attributes are available
|
||||
Attrs: &services.AuthenticateResponse_AuthTokenResponse{
|
||||
AuthTokenResponse: &authtokens.AuthToken{
|
||||
AccountId: "public-account_id",
|
||||
@@ -103,7 +148,7 @@ func TestAuthenticate_Tags(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "validate-request-filtering",
|
||||
name: "validate-callback-request-filtering",
|
||||
testEvent: &eventlogger.Event{
|
||||
Type: "test",
|
||||
CreatedAt: now,
|
||||
@@ -111,9 +156,75 @@ func TestAuthenticate_Tags(t *testing.T) {
|
||||
AuthMethodId: "public-auth-method-id",
|
||||
TokenType: "public-token-type",
|
||||
Command: "public-command",
|
||||
Attrs: &services.AuthenticateRequest_OidcAuthMethodAuthenticateTokenRequest{
|
||||
OidcAuthMethodAuthenticateTokenRequest: &authmethods.OidcAuthMethodAuthenticateTokenRequest{
|
||||
TokenId: "public-token-id",
|
||||
Attrs: &services.AuthenticateRequest_OidcAuthMethodAuthenticateCallbackRequest{
|
||||
OidcAuthMethodAuthenticateCallbackRequest: &authmethods.OidcAuthMethodAuthenticateCallbackRequest{
|
||||
Code: "secret-code",
|
||||
State: "public-state",
|
||||
Error: "public-error",
|
||||
ErrorDescription: "public-error_description",
|
||||
ErrorUri: "public-error_uri",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantEvent: &eventlogger.Event{
|
||||
Type: "test",
|
||||
CreatedAt: now,
|
||||
Payload: &services.AuthenticateRequest{
|
||||
AuthMethodId: "public-auth-method-id",
|
||||
TokenType: "public-token-type",
|
||||
Command: "public-command",
|
||||
Attrs: &services.AuthenticateRequest_OidcAuthMethodAuthenticateCallbackRequest{
|
||||
OidcAuthMethodAuthenticateCallbackRequest: &authmethods.OidcAuthMethodAuthenticateCallbackRequest{
|
||||
Code: encrypt.RedactedData,
|
||||
State: "public-state",
|
||||
Error: "public-error",
|
||||
ErrorDescription: "public-error_description",
|
||||
ErrorUri: "public-error_uri",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "validate-callback-response-filtering",
|
||||
testEvent: &eventlogger.Event{
|
||||
Type: "test",
|
||||
CreatedAt: now,
|
||||
Payload: &services.AuthenticateResponse{
|
||||
Command: "public-command",
|
||||
Attrs: &services.AuthenticateResponse_OidcAuthMethodAuthenticateCallbackResponse{
|
||||
OidcAuthMethodAuthenticateCallbackResponse: &authmethods.OidcAuthMethodAuthenticateCallbackResponse{
|
||||
FinalRedirectUrl: "public-final_redirect_url",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantEvent: &eventlogger.Event{
|
||||
Type: "test",
|
||||
CreatedAt: now,
|
||||
Payload: &services.AuthenticateResponse{
|
||||
Command: "public-command",
|
||||
Attrs: &services.AuthenticateResponse_OidcAuthMethodAuthenticateCallbackResponse{
|
||||
OidcAuthMethodAuthenticateCallbackResponse: &authmethods.OidcAuthMethodAuthenticateCallbackResponse{
|
||||
FinalRedirectUrl: "public-final_redirect_url",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "validate-token-request-filtering",
|
||||
testEvent: &eventlogger.Event{
|
||||
Type: "test",
|
||||
CreatedAt: now,
|
||||
Payload: &services.AuthenticateRequest{
|
||||
AuthMethodId: "public-auth-method-id",
|
||||
TokenType: "public-token-type",
|
||||
Command: "public-command",
|
||||
Attrs: &services.AuthenticateRequest_OidcAuthMethodAuthenticateTokenRequest{
|
||||
OidcAuthMethodAuthenticateTokenRequest: &authmethods.OidcAuthMethodAuthenticateTokenRequest{
|
||||
TokenId: "secret-token-id",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -125,7 +236,6 @@ func TestAuthenticate_Tags(t *testing.T) {
|
||||
AuthMethodId: "public-auth-method-id",
|
||||
TokenType: "public-token-type",
|
||||
Command: "public-command",
|
||||
// TODO(johanbrandhorst): update redaction once typed attributes are available
|
||||
Attrs: &services.AuthenticateRequest_OidcAuthMethodAuthenticateTokenRequest{
|
||||
OidcAuthMethodAuthenticateTokenRequest: &authmethods.OidcAuthMethodAuthenticateTokenRequest{
|
||||
TokenId: encrypt.RedactedData,
|
||||
@@ -134,6 +244,33 @@ func TestAuthenticate_Tags(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "validate-token-response-filtering",
|
||||
testEvent: &eventlogger.Event{
|
||||
Type: "test",
|
||||
CreatedAt: now,
|
||||
Payload: &services.AuthenticateResponse{
|
||||
Command: "public-command",
|
||||
Attrs: &services.AuthenticateResponse_OidcAuthMethodAuthenticateTokenResponse{
|
||||
OidcAuthMethodAuthenticateTokenResponse: &authmethods.OidcAuthMethodAuthenticateTokenResponse{
|
||||
Status: "public-status",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantEvent: &eventlogger.Event{
|
||||
Type: "test",
|
||||
CreatedAt: now,
|
||||
Payload: &services.AuthenticateResponse{
|
||||
Command: "public-command",
|
||||
Attrs: &services.AuthenticateResponse_OidcAuthMethodAuthenticateTokenResponse{
|
||||
OidcAuthMethodAuthenticateTokenResponse: &authmethods.OidcAuthMethodAuthenticateTokenResponse{
|
||||
Status: "public-status",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user