Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/metal-api/internal/service/v1/vpn.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ type VPNRequest struct {
Pid string `json:"pid" description:"project ID"`
Ephemeral bool `json:"ephemeral" description:"specifies if auth key should be ephemeral"`
Expiration *time.Duration `json:"expiration" description:"expiration time" optional:"true"`
Reason string `json:"reason" description:"reason why the consolepassword is requested, typically a incident number with short description"`
}
8 changes: 8 additions & 0 deletions cmd/metal-api/internal/service/vpn-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,21 @@ import (
type vpnResource struct {
webResource
headscaleClient *headscale.HeadscaleClient
reasonMinLength uint
}

// NewVPN returns a webservice for VPN specific endpoints.
func NewVPN(
log *slog.Logger,
headscaleClient *headscale.HeadscaleClient,
reasonMinLength uint,
) *restful.WebService {
r := vpnResource{
webResource: webResource{
log: log,
},
headscaleClient: headscaleClient,
reasonMinLength: reasonMinLength,
}

return r.webService()
Expand Down Expand Up @@ -74,6 +77,11 @@ func (r *vpnResource) getVPNAuthKey(request *restful.Request, response *restful.
return
}

if uint(len(requestPayload.Reason)) < r.reasonMinLength {
r.sendError(request, response, httperrors.BadRequest(fmt.Errorf("reason must be at least %d characters long", r.reasonMinLength)))
return
}

pid := requestPayload.Pid
if ok := r.headscaleClient.UserExists(request.Request.Context(), pid); !ok {
r.sendError(
Expand Down
2 changes: 1 addition & 1 deletion cmd/metal-api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ func initRestServices(searchAuditBackend auditing.Auditing, allAuditBackends []a
restful.DefaultContainer.Add(service.NewFilesystemLayout(logger.WithGroup("filesystem-layout-service"), ds))
restful.DefaultContainer.Add(service.NewSwitch(logger.WithGroup("switch-service"), ds))
restful.DefaultContainer.Add(healthService)
restful.DefaultContainer.Add(service.NewVPN(logger.WithGroup("vpn-service"), headscaleClient))
restful.DefaultContainer.Add(service.NewVPN(logger.WithGroup("vpn-service"), headscaleClient, reasonMinLength))
restful.DefaultContainer.Add(rest.NewVersion(moduleName, &rest.VersionOpts{
BasePath: service.BasePath,
MinClientVersion: minClientVersion.Original(),
Expand Down
7 changes: 6 additions & 1 deletion spec/metal-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -5891,11 +5891,16 @@
"pid": {
"description": "project ID",
"type": "string"
},
"reason": {
"description": "reason why the consolepassword is requested, typically a incident number with short description",
"type": "string"
}
},
"required": [
"ephemeral",
"pid"
"pid",
"reason"
]
},
"v1.VPNResponse": {
Expand Down