feat: Normalize fields across various Boundary components (#5599)
Normalizes various IP/Address/Host fields across Boundary resources/components to comply with IPv6 specifications.
This commit is contained in:
37 files changed
+1028
-348
No files matched your search
@@ -1061,8 +1061,12 @@ func validateCreateRequest(ctx context.Context, req *pbs.CreateAuthMethodRequest
|
||||
if err != nil {
|
||||
badFields[issuerField] = fmt.Sprintf("Cannot be parsed as a url. %v", err)
|
||||
}
|
||||
if !strutil.StrListContains([]string{"http", "https"}, iss.Scheme) {
|
||||
badFields[issuerField] = fmt.Sprintf("Must have schema %q or %q specified", "http", "https")
|
||||
if iss != nil {
|
||||
if !strutil.StrListContains([]string{"http", "https"}, iss.Scheme) {
|
||||
badFields[issuerField] = fmt.Sprintf("Must have schema %q or %q specified", "http", "https")
|
||||
}
|
||||
} else {
|
||||
badFields[issuerField] = "Cannot be parsed as a url"
|
||||
}
|
||||
}
|
||||
if attrs.GetDisableDiscoveredConfigValidation() {
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
|
||||
"github.com/hashicorp/boundary/internal/types/action"
|
||||
pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/authmethods"
|
||||
"github.com/hashicorp/go-secure-stdlib/parseutil"
|
||||
"google.golang.org/grpc/codes"
|
||||
)
|
||||
|
||||
@@ -419,6 +420,10 @@ func toStorageOidcAuthMethod(ctx context.Context, scopeId string, in *pb.AuthMet
|
||||
// Strip off everything after and including ".well-known/openid-configuration"
|
||||
// but leave the "/" attached to the end.
|
||||
iss = strings.SplitN(iss, ".well-known/", 2)[0]
|
||||
iss, err := parseutil.NormalizeAddr(iss)
|
||||
if err != nil {
|
||||
return nil, false, false, errors.Wrap(ctx, err, op, errors.WithMsg("cannot normalize issuer"), errors.WithCode(errors.InvalidParameter))
|
||||
}
|
||||
issuer, err := url.Parse(iss)
|
||||
if err != nil {
|
||||
return nil, false, false, errors.Wrap(ctx, err, op, errors.WithMsg("cannot parse issuer"), errors.WithCode(errors.InvalidParameter))
|
||||
@@ -426,6 +431,10 @@ func toStorageOidcAuthMethod(ctx context.Context, scopeId string, in *pb.AuthMet
|
||||
opts = append(opts, oidc.WithIssuer(issuer))
|
||||
}
|
||||
if apiUrl := strings.TrimSpace(attrs.GetApiUrlPrefix().GetValue()); apiUrl != "" {
|
||||
apiUrl, err := parseutil.NormalizeAddr(apiUrl)
|
||||
if err != nil {
|
||||
return nil, false, false, errors.Wrap(ctx, err, op, errors.WithMsg("cannot normalize api_url_prefix"), errors.WithCode(errors.InvalidParameter))
|
||||
}
|
||||
apiU, err := url.Parse(apiUrl)
|
||||
if err != nil {
|
||||
return nil, false, false, errors.Wrap(ctx, err, op, errors.WithMsg("cannot parse api_url_prefix"), errors.WithCode(errors.InvalidParameter))
|
||||
|
||||
@@ -454,6 +454,40 @@ func TestUpdate_OIDC(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Update Issuer IPv6",
|
||||
req: &pbs.UpdateAuthMethodRequest{
|
||||
UpdateMask: &field_mask.FieldMask{
|
||||
Paths: []string{"attributes.issuer"},
|
||||
},
|
||||
Item: &pb.AuthMethod{
|
||||
Attrs: func() *pb.AuthMethod_OidcAuthMethodsAttributes {
|
||||
f := proto.Clone(defaultAttributes.OidcAuthMethodsAttributes).(*pb.OidcAuthMethodAttributes)
|
||||
f.Issuer = wrapperspb.String("https://[2001:BEEF:0000:0000:0000:0000:0000:0001]:44344/v1/myissuer/.well-known/openid-configuration")
|
||||
f.DisableDiscoveredConfigValidation = true
|
||||
return &pb.AuthMethod_OidcAuthMethodsAttributes{OidcAuthMethodsAttributes: f}
|
||||
}(),
|
||||
},
|
||||
},
|
||||
res: &pbs.UpdateAuthMethodResponse{
|
||||
Item: &pb.AuthMethod{
|
||||
ScopeId: o.GetPublicId(),
|
||||
Name: &wrapperspb.StringValue{Value: "default"},
|
||||
Description: &wrapperspb.StringValue{Value: "default"},
|
||||
Type: oidc.Subtype.String(),
|
||||
Attrs: func() *pb.AuthMethod_OidcAuthMethodsAttributes {
|
||||
f := proto.Clone(defaultReadAttributes.OidcAuthMethodsAttributes).(*pb.OidcAuthMethodAttributes)
|
||||
f.Issuer = wrapperspb.String("https://[2001:beef::1]:44344/v1/myissuer/")
|
||||
f.DisableDiscoveredConfigValidation = true
|
||||
return &pb.AuthMethod_OidcAuthMethodsAttributes{OidcAuthMethodsAttributes: f}
|
||||
}(),
|
||||
|
||||
Scope: defaultScopeInfo,
|
||||
AuthorizedActions: oidcAuthorizedActions,
|
||||
AuthorizedCollectionActions: authorizedCollectionActions,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "invalid-issuer-port",
|
||||
req: &pbs.UpdateAuthMethodRequest{
|
||||
@@ -855,6 +889,38 @@ func TestUpdate_OIDC(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Change Api Url Prefix IPv6",
|
||||
req: &pbs.UpdateAuthMethodRequest{
|
||||
UpdateMask: &field_mask.FieldMask{
|
||||
Paths: []string{"attributes.api_url_prefix"},
|
||||
},
|
||||
Item: &pb.AuthMethod{
|
||||
Attrs: &pb.AuthMethod_OidcAuthMethodsAttributes{
|
||||
OidcAuthMethodsAttributes: &pb.OidcAuthMethodAttributes{
|
||||
ApiUrlPrefix: wrapperspb.String("https://[2001:BEEF:0000:0000:0000:0000:0000:0001]:44344/path"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
res: &pbs.UpdateAuthMethodResponse{
|
||||
Item: &pb.AuthMethod{
|
||||
ScopeId: o.GetPublicId(),
|
||||
Name: &wrapperspb.StringValue{Value: "default"},
|
||||
Description: &wrapperspb.StringValue{Value: "default"},
|
||||
Type: oidc.Subtype.String(),
|
||||
Attrs: func() *pb.AuthMethod_OidcAuthMethodsAttributes {
|
||||
f := proto.Clone(defaultReadAttributes.OidcAuthMethodsAttributes).(*pb.OidcAuthMethodAttributes)
|
||||
f.ApiUrlPrefix = wrapperspb.String("https://[2001:beef::1]:44344/path")
|
||||
f.CallbackUrl = "https://[2001:beef::1]:44344/path/v1/auth-methods/oidc:authenticate:callback"
|
||||
return &pb.AuthMethod_OidcAuthMethodsAttributes{OidcAuthMethodsAttributes: f}
|
||||
}(),
|
||||
Scope: defaultScopeInfo,
|
||||
AuthorizedActions: oidcAuthorizedActions,
|
||||
AuthorizedCollectionActions: authorizedCollectionActions,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Change Allowed Audiences",
|
||||
req: &pbs.UpdateAuthMethodRequest{
|
||||
@@ -1127,9 +1193,7 @@ func TestUpdate_OIDC(t *testing.T) {
|
||||
if got.Item.GetOidcAuthMethodsAttributes().CallbackUrl != "" {
|
||||
exp := tc.res.Item.GetOidcAuthMethodsAttributes().GetCallbackUrl()
|
||||
gVal := got.Item.GetOidcAuthMethodsAttributes().GetCallbackUrl()
|
||||
matches, err := regexp.MatchString(exp, gVal)
|
||||
require.NoError(err)
|
||||
assert.True(matches, "%q doesn't match %q", gVal, exp)
|
||||
assert.Equal(exp, gVal, "%q doesn't match %q", exp, gVal)
|
||||
}
|
||||
|
||||
assert.EqualValues(3, got.Item.Version)
|
||||
|
||||
Reference in new issue
Block a user