OIDC: make callback URL paths deterministic. (#1188)
This commit is contained in:
15 files changed
+51
-28
No files matched your search
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||
"github.com/hashicorp/boundary/globals"
|
||||
"github.com/hashicorp/boundary/internal/auth"
|
||||
"github.com/hashicorp/boundary/internal/auth/oidc"
|
||||
"github.com/hashicorp/boundary/internal/gen/controller/api/services"
|
||||
"github.com/hashicorp/boundary/internal/servers/controller/handlers/accounts"
|
||||
"github.com/hashicorp/boundary/internal/servers/controller/handlers/authmethods"
|
||||
@@ -361,6 +362,28 @@ func wrapHandlerWithCallbackInterceptor(h http.Handler, c *Controller) http.Hand
|
||||
for k := range req.Form {
|
||||
values[k] = req.Form.Get(k)
|
||||
}
|
||||
|
||||
if strings.HasSuffix(req.URL.Path, "oidc:authenticate") {
|
||||
if s, ok := values["state"].(string); ok {
|
||||
stateWrapper, err := oidc.UnwrapMessage(context.Background(), s)
|
||||
if err != nil {
|
||||
c.logger.Trace("callback error marshaling state", "method", req.Method, "url", req.URL.RequestURI(), "error", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if stateWrapper.AuthMethodId == "" {
|
||||
c.logger.Trace("callback error: missing auth method id", "method", req.Method, "url", req.URL.RequestURI())
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
stripped := strings.TrimSuffix(req.URL.Path, "oidc:authenticate")
|
||||
req.URL.Path = fmt.Sprintf("%s%s:authenticate", stripped, stateWrapper.AuthMethodId)
|
||||
} else {
|
||||
c.logger.Trace("callback error: missing state parameter", "method", req.Method, "url", req.URL.RequestURI())
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
attrs.Attributes = values
|
||||
}
|
||||
|
||||
|
||||
@@ -687,7 +687,7 @@ func toAuthMethodProto(in auth.AuthMethod, opt ...handlers.Option) (*pb.AuthMeth
|
||||
}
|
||||
if len(i.GetApiUrl()) > 0 {
|
||||
attrs.ApiUrlPrefix = wrapperspb.String(i.GetApiUrl())
|
||||
attrs.CallbackUrl = fmt.Sprintf("%s/v1/auth-methods/%s:authenticate:callback", i.GetApiUrl(), i.GetPublicId())
|
||||
attrs.CallbackUrl = fmt.Sprintf("%s/v1/auth-methods/oidc:authenticate:callback", i.GetApiUrl())
|
||||
}
|
||||
switch i.GetMaxAge() {
|
||||
case 0:
|
||||
|
||||
@@ -126,7 +126,7 @@ func TestGet(t *testing.T) {
|
||||
"client_secret_hmac": structpb.NewStringValue("<hmac>"),
|
||||
"state": structpb.NewStringValue(string(oidc.InactiveState)),
|
||||
"api_url_prefix": structpb.NewStringValue("https://api.com"),
|
||||
"callback_url": structpb.NewStringValue(fmt.Sprintf(oidc.CallbackEndpoint, "https://api.com", oidcam.GetPublicId())),
|
||||
"callback_url": structpb.NewStringValue(fmt.Sprintf(oidc.CallbackEndpoint, "https://api.com")),
|
||||
}},
|
||||
Version: 1,
|
||||
Scope: &scopepb.ScopeInfo{
|
||||
@@ -246,7 +246,7 @@ func TestList(t *testing.T) {
|
||||
"client_secret_hmac": structpb.NewStringValue("<hmac>"),
|
||||
"state": structpb.NewStringValue(string(oidc.ActivePublicState)),
|
||||
"api_url_prefix": structpb.NewStringValue("https://api.com"),
|
||||
"callback_url": structpb.NewStringValue(fmt.Sprintf(oidc.CallbackEndpoint, "https://api.com", oidcam.GetPublicId())),
|
||||
"callback_url": structpb.NewStringValue(fmt.Sprintf(oidc.CallbackEndpoint, "https://api.com")),
|
||||
"signing_algorithms": func() *structpb.Value {
|
||||
lv, _ := structpb.NewList([]interface{}{string(oidc.EdDSA)})
|
||||
return structpb.NewListValue(lv)
|
||||
@@ -591,7 +591,7 @@ func TestCreate(t *testing.T) {
|
||||
"client_secret_hmac": structpb.NewStringValue("<hmac>"),
|
||||
"state": structpb.NewStringValue(string(oidc.InactiveState)),
|
||||
"api_url_prefix": structpb.NewStringValue("https://callback.prefix:9281/path"),
|
||||
"callback_url": structpb.NewStringValue(fmt.Sprintf("https://callback.prefix:9281/path/v1/auth-methods/%s_[0-9A-z]*:authenticate:callback", oidc.AuthMethodPrefix)),
|
||||
"callback_url": structpb.NewStringValue("https://callback.prefix:9281/path/v1/auth-methods/oidc:authenticate:callback"),
|
||||
"allowed_audiences": func() *structpb.Value {
|
||||
lv, _ := structpb.NewList([]interface{}{"foo", "bar"})
|
||||
return structpb.NewListValue(lv)
|
||||
|
||||
@@ -118,7 +118,7 @@ func getSetup(t *testing.T) setup {
|
||||
oidc.WithCertificates(ret.testProviderCaCert...),
|
||||
)
|
||||
|
||||
ret.testProviderAllowedRedirect = fmt.Sprintf(oidc.CallbackEndpoint, ret.testController.URL, ret.authMethod.PublicId)
|
||||
ret.testProviderAllowedRedirect = fmt.Sprintf(oidc.CallbackEndpoint, ret.testController.URL)
|
||||
ret.testProvider.SetAllowedRedirectURIs([]string{ret.testProviderAllowedRedirect})
|
||||
|
||||
r, err := ret.oidcRepoFn()
|
||||
@@ -288,7 +288,7 @@ func TestUpdate_OIDC(t *testing.T) {
|
||||
"client_secret_hmac": structpb.NewStringValue("<hmac>"),
|
||||
"state": structpb.NewStringValue(string(oidc.ActivePrivateState)),
|
||||
"api_url_prefix": structpb.NewStringValue("http://example.com"),
|
||||
"callback_url": structpb.NewStringValue(fmt.Sprintf("http://example.com/v1/auth-methods/%s_[0-9A-z]*:authenticate:callback", oidc.AuthMethodPrefix)),
|
||||
"callback_url": structpb.NewStringValue("http://example.com/v1/auth-methods/oidc:authenticate:callback"),
|
||||
"idp_ca_certs": func() *structpb.Value {
|
||||
lv, _ := structpb.NewList([]interface{}{tp.CACert()})
|
||||
return structpb.NewListValue(lv)
|
||||
@@ -817,7 +817,7 @@ func TestUpdate_OIDC(t *testing.T) {
|
||||
Fields: func() map[string]*structpb.Value {
|
||||
f := defaultReadAttributeFields()
|
||||
f["api_url_prefix"] = structpb.NewStringValue("https://callback.prefix:9281/path")
|
||||
f["callback_url"] = structpb.NewStringValue(fmt.Sprintf("https://callback.prefix:9281/path/v1/auth-methods/%s_[0-9A-z]*:authenticate:callback", oidc.AuthMethodPrefix))
|
||||
f["callback_url"] = structpb.NewStringValue("https://callback.prefix:9281/path/v1/auth-methods/oidc:authenticate:callback")
|
||||
return f
|
||||
}(),
|
||||
},
|
||||
@@ -1102,7 +1102,7 @@ func TestUpdate_OIDCDryRun(t *testing.T) {
|
||||
AuthorizedCollectionActions: authorizedCollectionActions,
|
||||
Attributes: &structpb.Struct{Fields: map[string]*structpb.Value{
|
||||
"api_url_prefix": structpb.NewStringValue(am.GetApiUrl()),
|
||||
"callback_url": structpb.NewStringValue(fmt.Sprintf("%s/v1/auth-methods/%s:authenticate:callback", am.GetApiUrl(), am.GetPublicId())),
|
||||
"callback_url": structpb.NewStringValue(fmt.Sprintf("%s/v1/auth-methods/oidc:authenticate:callback", am.GetApiUrl())),
|
||||
"client_id": structpb.NewStringValue(am.GetClientId()),
|
||||
"client_secret_hmac": structpb.NewStringValue(am.GetClientSecretHmac()),
|
||||
"issuer": structpb.NewStringValue(am.GetIssuer()),
|
||||
@@ -1284,7 +1284,7 @@ func TestChangeState_OIDC(t *testing.T) {
|
||||
"client_id": structpb.NewStringValue(tpClientId),
|
||||
"client_secret_hmac": structpb.NewStringValue("<hmac>"),
|
||||
"state": structpb.NewStringValue(string(oidc.InactiveState)),
|
||||
"callback_url": structpb.NewStringValue("https://example.callback:58/v1/auth-methods/amoidc_[0-9A-z]*:authenticate:callback"),
|
||||
"callback_url": structpb.NewStringValue("https://example.callback:58/v1/auth-methods/oidc:authenticate:callback"),
|
||||
"api_url_prefix": structpb.NewStringValue("https://example.callback:58"),
|
||||
"signing_algorithms": signingAlg,
|
||||
"idp_ca_certs": certs,
|
||||
|
||||
Reference in new issue
Block a user