-
Notifications
You must be signed in to change notification settings - Fork 339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(kuma-cp) server for managing provided ca #473
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
479e153
feat(kuma-cp) server for managing provided ca
jakubdyszkiewicz 35ec7de
feat(kuma-cp) move kuma-api errors to core/rest/erors
jakubdyszkiewicz 02faedb
feat(kuma-cp) change signing cert return to pointer
jakubdyszkiewicz dd6e826
feat(kuma-cp) config for admin server
jakubdyszkiewicz af96260
feat(kuma-cp) add token generator webservice
jakubdyszkiewicz 1d0c986
feat(kuma-cp) switch to using admin server
jakubdyszkiewicz 4064d81
feat(kuma-cp) autoconfig old config values
jakubdyszkiewicz 94335b2
feat(kuma-cp) removed dataplane token server
jakubdyszkiewicz b93b9d0
feat(kuma-cp) add tests for overriding admin server config
jakubdyszkiewicz 6d41597
feat(kuma-cp) rename config to apis dataplane token
jakubdyszkiewicz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -7,39 +7,60 @@ import ( | |
|
||
func DefaultAdminServerConfig() *AdminServerConfig { | ||
return &AdminServerConfig{ | ||
Enabled: true, | ||
Local: DefaultLocalAdminServerConfig(), | ||
Public: DefaultPublicAdminServerConfig(), | ||
DataplaneTokenWs: DefaultDataplaneTokenWsConfig(), | ||
Local: DefaultLocalAdminServerConfig(), | ||
Public: DefaultPublicAdminServerConfig(), | ||
} | ||
} | ||
|
||
var _ config.Config = &AdminServerConfig{} | ||
|
||
// Admin Server configuration | ||
type AdminServerConfig struct { | ||
// If true then Admin Server and token verification is enabled | ||
Enabled bool `yaml:"enabled" envconfig:"kuma_admin_server_enabled"` | ||
// Configuration for Dataplane Token Webservice | ||
DataplaneTokenWs *DataplaneTokenWsConfig `yaml:"dataplaneTokenWs"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Name Let's use the same approach as in E.g.,
|
||
// Local configuration of server that is available only on localhost | ||
Local *LocalAdminServerConfig `yaml:"local"` | ||
// Public configuration of server that is available on public interface | ||
Public *PublicAdminServerConfig `yaml:"public"` | ||
} | ||
|
||
var _ config.Config = &DataplaneTokenWsConfig{} | ||
|
||
func DefaultDataplaneTokenWsConfig() *DataplaneTokenWsConfig { | ||
return &DataplaneTokenWsConfig{ | ||
Enabled: true, | ||
} | ||
} | ||
|
||
type DataplaneTokenWsConfig struct { | ||
// If true then Dataplane Token WS and token verification is enabled | ||
Enabled bool `yaml:"enabled" envconfig:"kuma_admin_server_dataplane_token_ws_enabled"` | ||
} | ||
|
||
func (d *DataplaneTokenWsConfig) Sanitize() { | ||
} | ||
|
||
func (d *DataplaneTokenWsConfig) Validate() error { | ||
return nil | ||
} | ||
|
||
func (i *AdminServerConfig) Sanitize() { | ||
i.DataplaneTokenWs.Sanitize() | ||
i.Public.Sanitize() | ||
i.Local.Sanitize() | ||
} | ||
|
||
func (i *AdminServerConfig) Validate() error { | ||
if err := i.DataplaneTokenWs.Validate(); err != nil { | ||
return errors.Wrap(err, "Dataplane Token Ws validation failed") | ||
} | ||
if err := i.Local.Validate(); err != nil { | ||
return errors.Wrap(err, "Local validation failed") | ||
} | ||
if err := i.Public.Validate(); err != nil { | ||
return errors.Wrap(err, "Public validation failed") | ||
} | ||
if !i.Enabled && i.Public.Enabled { | ||
return errors.New("Public.Enabled cannot be true when server is disabled.") | ||
} | ||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package server | ||
|
||
import ( | ||
"github.com/Kong/kuma/pkg/core/rest/errors" | ||
"github.com/Kong/kuma/pkg/core/validators" | ||
"github.com/Kong/kuma/pkg/tokens/builtin/issuer" | ||
"github.com/Kong/kuma/pkg/tokens/builtin/server/types" | ||
"github.com/emicklei/go-restful" | ||
"net/http" | ||
) | ||
|
||
type DataplaneTokenWebService struct { | ||
Issuer issuer.DataplaneTokenIssuer | ||
} | ||
|
||
func NewWebservice(issuer issuer.DataplaneTokenIssuer) *restful.WebService { | ||
ws := DataplaneTokenWebService{ | ||
Issuer: issuer, | ||
} | ||
return ws.createWs() | ||
} | ||
|
||
func (d *DataplaneTokenWebService) createWs() *restful.WebService { | ||
ws := new(restful.WebService). | ||
Consumes(restful.MIME_JSON). | ||
Produces(restful.MIME_JSON) | ||
ws.Path("/tokens"). | ||
Route(ws.POST("").To(d.handleIdentityRequest)) | ||
return ws | ||
} | ||
|
||
func (d *DataplaneTokenWebService) handleIdentityRequest(request *restful.Request, response *restful.Response) { | ||
idReq := types.DataplaneTokenRequest{} | ||
if err := request.ReadEntity(&idReq); err != nil { | ||
log.Error(err, "Could not read a request") | ||
response.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
verr := validators.ValidationError{} | ||
if idReq.Name == "" { | ||
verr.AddViolation("name", "cannot be empty") | ||
} | ||
if idReq.Mesh == "" { | ||
verr.AddViolation("mesh", "cannot be empty") | ||
} | ||
if verr.HasViolations() { | ||
errors.HandleError(response, verr.OrNil(), "Invalid request") | ||
return | ||
} | ||
|
||
token, err := d.Issuer.Generate(idReq.ToProxyId()) | ||
if err != nil { | ||
errors.HandleError(response, err, "Could not issue a token") | ||
return | ||
} | ||
|
||
response.Header().Set("content-type", "text/plain") | ||
if _, err := response.Write([]byte(token)); err != nil { | ||
log.Error(err, "Could write a response") | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a swallowed error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch!