-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kuma-cp) user token with RSA256 (#2992)
Signed-off-by: Jakub Dyszkiewicz <jakub.dyszkiewicz@gmail.com>
- Loading branch information
1 parent
b805788
commit 4c0f561
Showing
12 changed files
with
210 additions
and
95 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
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
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
47 changes: 47 additions & 0 deletions
47
pkg/plugins/authn/api-server/tokens/issuer/signing_key_accessor.go
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,47 @@ | ||
package issuer | ||
|
||
import ( | ||
"context" | ||
"crypto/rsa" | ||
|
||
"github.com/pkg/errors" | ||
|
||
"github.com/kumahq/kuma/pkg/core/resources/apis/system" | ||
"github.com/kumahq/kuma/pkg/core/resources/manager" | ||
"github.com/kumahq/kuma/pkg/core/resources/store" | ||
util_rsa "github.com/kumahq/kuma/pkg/util/rsa" | ||
) | ||
|
||
type SigningKeyAccessor interface { | ||
GetSigningPublicKey(serialNumber int) (*rsa.PublicKey, error) | ||
} | ||
|
||
type signingKeyAccessor struct { | ||
resManager manager.ResourceManager | ||
} | ||
|
||
var _ SigningKeyAccessor = &signingKeyAccessor{} | ||
|
||
func NewSigningKeyAccessor(resManager manager.ResourceManager) SigningKeyAccessor { | ||
return &signingKeyAccessor{ | ||
resManager: resManager, | ||
} | ||
} | ||
|
||
func (s *signingKeyAccessor) GetSigningPublicKey(serialNumber int) (*rsa.PublicKey, error) { | ||
resource := system.NewGlobalSecretResource() | ||
if err := s.resManager.Get(context.Background(), resource, store.GetBy(SigningKeyResourceKey(serialNumber))); err != nil { | ||
if store.IsResourceNotFound(err) { | ||
return nil, &SigningKeyNotFound{ | ||
SerialNumber: serialNumber, | ||
} | ||
} | ||
return nil, errors.Wrap(err, "could not retrieve signing key") | ||
} | ||
|
||
key, err := util_rsa.FromPEMBytes(resource.Spec.GetData().GetValue()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &key.PublicKey, nil | ||
} |
Oops, something went wrong.