-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose /.well-known/jwks-okta for Okta API services type App
- Loading branch information
Showing
7 changed files
with
150 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Teleport | ||
// Copyright (C) 2024 Gravitational, Inc. | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package web | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/gravitational/trace" | ||
|
||
"github.com/gravitational/teleport/api/types" | ||
"github.com/gravitational/teleport/lib/jwt" | ||
) | ||
|
||
func (h *Handler) jwks(ctx context.Context, caType types.CertAuthType, includeBlankKeyID bool) (*JWKSResponse, error) { | ||
clusterName, err := h.GetProxyClient().GetDomainName(ctx) | ||
if err != nil { | ||
return nil, trace.Wrap(err) | ||
} | ||
|
||
// Fetch the JWT public keys only. | ||
ca, err := h.GetProxyClient().GetCertAuthority(ctx, types.CertAuthID{ | ||
Type: caType, | ||
DomainName: clusterName, | ||
}, false /* loadKeys */) | ||
if err != nil { | ||
return nil, trace.Wrap(err) | ||
} | ||
|
||
pairs := ca.GetTrustedJWTKeyPairs() | ||
|
||
// Create response and allocate space for the keys. | ||
var resp JWKSResponse | ||
resp.Keys = make([]jwt.JWK, 0, len(pairs)) | ||
|
||
// Loop over and all add public keys in JWK format. | ||
for _, key := range pairs { | ||
jwk, err := jwt.MarshalJWK(key.PublicKey) | ||
if err != nil { | ||
return nil, trace.Wrap(err) | ||
} | ||
resp.Keys = append(resp.Keys, jwk) | ||
|
||
// Return an additional copy of the same JWK | ||
// with KeyID set to the empty string for compatibility. | ||
if includeBlankKeyID { | ||
jwk.KeyID = "" | ||
resp.Keys = append(resp.Keys, jwk) | ||
} | ||
} | ||
return &resp, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Teleport | ||
// Copyright (C) 2024 Gravitational, Inc. | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package web | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/julienschmidt/httprouter" | ||
|
||
"github.com/gravitational/teleport/api/types" | ||
) | ||
|
||
// jwksOkta returns public keys used to verify JWT tokens signed for use with Okta API Service App | ||
// machine-to-machine authentication. | ||
// https://developer.okta.com/docs/guides/implement-oauth-for-okta-serviceapp/main/ | ||
func (h *Handler) jwksOkta(_ http.ResponseWriter, r *http.Request, _ httprouter.Params) (interface{}, error) { | ||
return h.jwks(r.Context(), types.OktaCA, false /* includeBlankKeyID */) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Teleport | ||
// Copyright (C) 2024 Gravitational, Inc. | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package web | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// TestJWKSOktaPublicEndpoint ensures the public endpoint for the Okta API Service App integration | ||
// is available. | ||
func TestJWKSOktaPublicEndpoint(t *testing.T) { | ||
t.Parallel() | ||
ctx := context.Background() | ||
env := newWebPack(t, 1) | ||
proxy := env.proxies[0] | ||
|
||
publicClt := proxy.newClient(t) | ||
|
||
resp, err := publicClt.Get(ctx, publicClt.Endpoint(".well-known/jwks-okta"), nil) | ||
require.NoError(t, err) | ||
|
||
var gotKeys JWKSResponse | ||
err = json.Unmarshal(resp.Bytes(), &gotKeys) | ||
require.NoError(t, err) | ||
|
||
require.Len(t, gotKeys.Keys, 1) | ||
require.NotEmpty(t, gotKeys.Keys[0].KeyID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters