Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit 702455a

Browse files
author
Janos Bonic
committed
Fixes OpenAPI generation
1 parent 2bdaf03 commit 702455a

12 files changed

Lines changed: 256 additions & 109 deletions

File tree

auth/protocol.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import (
88
//
99
// swagger:model PasswordAuthRequest
1010
type PasswordAuthRequest struct {
11+
// swagger:allOf
1112
metadata.ConnectionAuthPendingMetadata `json:",inline"`
1213

1314
// Password the user provided for authentication.
1415
//
1516
// required: true
17+
// in: body
1618
// swagger:strfmt Base64
1719
Password string `json:"passwordBase64"`
1820
}
@@ -21,8 +23,11 @@ type PasswordAuthRequest struct {
2123
//
2224
// swagger:model PublicKeyAuthRequest
2325
type PublicKeyAuthRequest struct {
26+
// swagger:allOf
2427
metadata.ConnectionAuthPendingMetadata `json:",inline"`
2528

29+
// in: body
30+
// required: true
2631
PublicKey `json:",inline"`
2732
}
2833

@@ -32,14 +37,24 @@ type PublicKeyAuthRequest struct {
3237
//
3338
// swagger:model AuthorizationRequest
3439
type AuthorizationRequest struct {
40+
// swagger:allOf
3541
metadata.ConnectionAuthenticatedMetadata `json:",inline"`
3642
}
3743

3844
// ResponseBody is a response to authentication requests.
3945
//
4046
// swagger:model AuthResponseBody
4147
type ResponseBody struct {
42-
metadata.ConnectionAuthenticatedMetadata `json:",inline"`
48+
metadata.DynamicMetadata `json:",inline"`
49+
50+
// AuthenticatedUsername contains the username that was actually verified. This may differ from LoginUsername when,
51+
// for example OAuth2 or Kerberos authentication is used. This field is empty until the authentication phase is
52+
// completed.
53+
//
54+
// required: false
55+
// in: body
56+
// example: systemusername
57+
AuthenticatedUsername string `json:"authenticatedUsername,omitempty"`
4358

4459
// Success indicates if the authentication was successful.
4560
//
@@ -55,5 +70,6 @@ type Response struct {
5570
// The response body
5671
//
5772
// in: body
58-
ResponseBody
73+
// required: true
74+
Body ResponseBody
5975
}

auth/pubkey.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ type PublicKey struct {
55
// PublicKey is the key in the authorized key format.
66
//
77
// required: true
8+
// example: ssh-rsa ...
89
PublicKey string `json:"publicKey"`
910
}

cmd/containerssh-testauthconfigserver/main.go

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ContainerSSH Authentication and Configuration Server
22
//
33
// This OpenAPI document describes the API endpoints that are required for implementing an authentication
4-
// and configuration server for ContainerSSH. (See https://github.com/containerssh/libcontainerssh for details.)
4+
// and configuration server for ContainerSSH. (See https://github.com/containerssh/containerssh for details.)
55
//
66
// Schemes: http, https
77
// Host: localhost
@@ -24,23 +24,23 @@ import (
2424
"os/signal"
2525
"syscall"
2626

27-
publicAuth "go.containerssh.io/libcontainerssh/auth"
28-
"go.containerssh.io/libcontainerssh/config"
29-
configWebhook "go.containerssh.io/libcontainerssh/config/webhook"
30-
"go.containerssh.io/libcontainerssh/http"
31-
"go.containerssh.io/libcontainerssh/internal/auth"
32-
"go.containerssh.io/libcontainerssh/log"
33-
"go.containerssh.io/libcontainerssh/metadata"
34-
"go.containerssh.io/libcontainerssh/service"
3527
"github.com/docker/docker/api/types/container"
28+
"go.containerssh.io/libcontainerssh/auth"
29+
authWebhook "go.containerssh.io/libcontainerssh/auth/webhook"
30+
"go.containerssh.io/libcontainerssh/config"
31+
configWebhook "go.containerssh.io/libcontainerssh/config/webhook"
32+
"go.containerssh.io/libcontainerssh/http"
33+
"go.containerssh.io/libcontainerssh/log"
34+
"go.containerssh.io/libcontainerssh/metadata"
35+
"go.containerssh.io/libcontainerssh/service"
3636
)
3737

3838
type authHandler struct {
3939
}
4040

41-
// swagger:operation POST /password Authentication authPassword
41+
// swagger:operation POST /authz Authorization authorize
4242
//
43-
// Password authentication
43+
// Authorization
4444
//
4545
// ---
4646
// parameters:
@@ -53,22 +53,17 @@ type authHandler struct {
5353
// responses:
5454
// "200":
5555
// "$ref": "#/responses/AuthResponse"
56-
func (a *authHandler) OnPassword(meta metadata.ConnectionAuthPendingMetadata, Password []byte) (
56+
func (a *authHandler) OnAuthorization(meta metadata.ConnectionAuthenticatedMetadata) (
5757
bool,
5858
metadata.ConnectionAuthenticatedMetadata,
5959
error,
6060
) {
61-
if os.Getenv("CONTAINERSSH_ALLOW_ALL") == "1" ||
62-
meta.Username == "foo" ||
63-
meta.Username == "busybox" {
64-
return true, meta.Authenticated(meta.Username), nil
65-
}
66-
return false, meta.AuthFailed(), nil
61+
return true, meta.Authenticated(meta.Username), nil
6762
}
6863

69-
// swagger:operation POST /pubkey Authentication authPubKey
64+
// swagger:operation POST /password Authentication authPassword
7065
//
71-
// Public key authentication
66+
// Password authentication
7267
//
7368
// ---
7469
// parameters:
@@ -77,37 +72,39 @@ func (a *authHandler) OnPassword(meta metadata.ConnectionAuthPendingMetadata, Pa
7772
// description: The authentication request
7873
// required: true
7974
// schema:
80-
// "$ref": "#/definitions/PublicKeyAuthRequest"
75+
// "$ref": "#/definitions/PasswordAuthRequest"
8176
// responses:
8277
// "200":
8378
// "$ref": "#/responses/AuthResponse"
84-
func (a *authHandler) OnPubKey(meta metadata.ConnectionAuthPendingMetadata, publicKey publicAuth.PublicKey) (
79+
func (a *authHandler) OnPassword(metadata metadata.ConnectionAuthPendingMetadata, password []byte) (
8580
bool,
8681
metadata.ConnectionAuthenticatedMetadata,
8782
error,
8883
) {
89-
if meta.Username == "foo" || meta.Username == "busybox" {
90-
return true, meta.Authenticated(meta.Username), nil
84+
if os.Getenv("CONTAINERSSH_ALLOW_ALL") == "1" ||
85+
metadata.Username == "foo" ||
86+
metadata.Username == "busybox" {
87+
return true, metadata.Authenticated(metadata.Username), nil
9188
}
92-
return false, meta.AuthFailed(), nil
89+
return false, metadata.AuthFailed(), nil
9390
}
9491

95-
// swagger:operation POST /authz Authentication authz
92+
// swagger:operation POST /pubkey Authentication authPubKey
9693
//
97-
// Authorization
94+
// Public key authentication
9895
//
9996
// ---
10097
// parameters:
10198
// - name: request
10299
// in: body
103-
// description: The authorization request
100+
// description: The authentication request
104101
// required: true
105102
// schema:
106-
// "$ref": "#/definitions/AuthorizationRequest"
103+
// "$ref": "#/definitions/PublicKeyAuthRequest"
107104
// responses:
108105
// "200":
109106
// "$ref": "#/responses/AuthResponse"
110-
func (a *authHandler) OnAuthorization(meta metadata.ConnectionAuthenticatedMetadata) (
107+
func (a *authHandler) OnPubKey(meta metadata.ConnectionAuthPendingMetadata, publicKey auth.PublicKey) (
111108
bool,
112109
metadata.ConnectionAuthenticatedMetadata,
113110
error,
@@ -168,15 +165,17 @@ func (h *handler) ServeHTTP(writer goHttp.ResponseWriter, request *goHttp.Reques
168165
}
169166

170167
func main() {
171-
logger, err := log.NewLogger(config.LogConfig{
172-
Level: config.LogLevelDebug,
173-
Format: config.LogFormatLJSON,
174-
Destination: config.LogDestinationStdout,
175-
})
168+
logger, err := log.NewLogger(
169+
config.LogConfig{
170+
Level: config.LogLevelDebug,
171+
Format: config.LogFormatLJSON,
172+
Destination: config.LogDestinationStdout,
173+
},
174+
)
176175
if err != nil {
177176
panic(err)
178177
}
179-
authHTTPHandler := auth.NewHandler(&authHandler{}, logger)
178+
authHTTPHandler := authWebhook.NewHandler(&authHandler{}, logger)
180179
configHTTPHandler, err := configWebhook.NewHandler(&configHandler{}, logger)
181180
if err != nil {
182181
panic(err)
@@ -207,10 +206,12 @@ func main() {
207206
func(s service.Service, l service.Lifecycle) {
208207
println("Test Auth-Config Server is now running...")
209208
close(running)
210-
}).OnStopped(
209+
},
210+
).OnStopped(
211211
func(s service.Service, l service.Lifecycle) {
212212
close(stopped)
213-
})
213+
},
214+
)
214215
exitSignalList := []os.Signal{os.Interrupt, os.Kill, syscall.SIGINT, syscall.SIGTERM}
215216
exitSignals := make(chan os.Signal, 1)
216217
signal.Notify(exitSignals, exitSignalList...)

config/appconfig.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
)
99

1010
// AppConfig is the root configuration object of ContainerSSH.
11-
//goland:noinspection GoDeprecation
1211
type AppConfig struct {
1312
// SSH contains the configuration for the SSH server.
1413
// swagger:ignore
@@ -32,23 +31,30 @@ type AppConfig struct {
3231
// swagger:ignore
3332
Audit AuditLogConfig `json:"audit" yaml:"audit"`
3433
// Health contains the configuration for the health check service.
34+
// swagger:ignore
3535
Health HealthConfig `json:"health" yaml:"health"`
3636

3737
// Security contains the security restrictions on what can be executed. This option can be changed from the config
3838
// server.
3939
Security SecurityConfig `json:"security" yaml:"security"`
4040
// Backend defines which backend to use. This option can be changed from the config server.
41+
//
42+
// example: docker
4143
Backend Backend `json:"backend" yaml:"backend" default:"docker"`
4244
// Docker contains the configuration for the docker backend. This option can be changed from the config server.
4345
Docker DockerConfig `json:"docker,omitempty" yaml:"docker"`
4446
// DockerRun is a placeholder for the removed DockerRun backend. Filling this with anything but nil will yield a
4547
// validation error.
48+
//
49+
// swagger:ignore
4650
DockerRun interface{} `json:"dockerrun,omitempty"`
4751
// Kubernetes contains the configuration for the kubernetes backend. This option can be changed from the config
4852
// server.
4953
Kubernetes KubernetesConfig `json:"kubernetes,omitempty" yaml:"kubernetes"`
5054
// KubeRun is a placeholder for the removed DockerRun backend. Filling this with anything but nil will yield a
5155
// validation error.
56+
//
57+
// swagger:ignore
5258
KubeRun interface{} `json:"kuberun,omitempty"`
5359
// SSHProxy is the configuration for the SSH proxy backend, which forwards requests to a backing SSH server.
5460
SSHProxy SSHProxyConfig `json:"sshproxy,omitempty" yaml:"sshproxy"`

config/docker.go

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
)
1414

1515
// DockerConfig is the base configuration structure of the Docker backend.
16+
//
17+
// swagger:model DockerConfig
1618
type DockerConfig struct {
1719
// Connection configures how to connect to dockerd
1820
Connection DockerConnectionConfig `json:"connection" yaml:"connection"`
@@ -68,6 +70,8 @@ func parseRawDuration(rawValue interface{}, d *time.Duration) error {
6870
// DockerExecutionMode determines when a container is launched.
6971
// DockerExecutionModeConnection launches one container per SSH connection (default), while DockerExecutionModeSession launches
7072
// one container per SSH session.
73+
//
74+
// swagger:enum DockerExecutionMode
7175
type DockerExecutionMode string
7276

7377
const (
@@ -90,7 +94,8 @@ func (e DockerExecutionMode) Validate() error {
9094
}
9195

9296
// DockerExecutionConfig contains the configuration of what container to run in Docker.
93-
//goland:noinspection GoVetStructTag
97+
//
98+
// swagger:model DockerExecutionConfig
9499
type DockerExecutionConfig struct {
95100
// Launch contains the Docker-specific launch configuration.
96101
Launch DockerLaunchConfig `json:",inline" yaml:",inline"`
@@ -166,6 +171,8 @@ func (c DockerExecutionConfig) Validate() error {
166171
// the "latest" tag was specified.
167172
// - ImagePullPolicyNever means that the image will be never pulled, and if the image is not available locally the
168173
// connection will fail.
174+
//
175+
// swagger:enum DockerImagePullPolicy
169176
type DockerImagePullPolicy string
170177

171178
const (
@@ -194,18 +201,50 @@ func (p DockerImagePullPolicy) Validate() error {
194201
}
195202

196203
// DockerTimeoutConfig drives the various timeouts in the Docker backend.
204+
//
205+
// swagger:model DockerTimeoutConfig
197206
type DockerTimeoutConfig struct {
198-
// ContainerStart is the maximum time starting a container may take.
207+
// ContainerStart is the maximum time starting a container may take. It may be configured as an integer in
208+
// nanoseconds or as a time formatting string.
209+
//
210+
// required: false
211+
// example: 60s
212+
// swagger:type string
199213
ContainerStart time.Duration `json:"containerStart" yaml:"containerStart" default:"60s"`
200-
// ContainerStop is the maximum time to wait for a container to stop. This should always be set higher than the Docker StopTimeout.
214+
// ContainerStop is the maximum time to wait for a container to stop.
215+
// This should always be set higher than the Docker StopTimeout. It may be configured as an integer in
216+
// nanoseconds or as a time formatting string.
217+
//
218+
// required: true
219+
// example: 60s
220+
// swagger:type string
201221
ContainerStop time.Duration `json:"containerStop" yaml:"containerStop" default:"60s"`
202-
// CommandStart sets the maximum time starting a command may take.
222+
// CommandStart sets the maximum time starting a command may take. It may be configured as an integer in
223+
// nanoseconds or as a time formatting string.
224+
//
225+
// required: true
226+
// example: 60s
227+
// swagger:type string
203228
CommandStart time.Duration `json:"commandStart" yaml:"commandStart" default:"60s"`
204-
// Signal sets the maximum time sending a signal may take.
229+
// Signal sets the maximum time sending a signal may take. It may be configured as an integer in
230+
// nanoseconds or as a time formatting string.
231+
//
232+
// required: true
233+
// example: 60s
234+
// swagger:type string
205235
Signal time.Duration `json:"signal" yaml:"signal" default:"60s"`
206-
// Signal sets the maximum time setting the window size may take.
236+
// Signal sets the maximum time setting the window size may take. It may be configured as an integer in
237+
// nanoseconds or as a time formatting string.
238+
//
239+
// required: true
240+
// example: 60s
241+
// swagger:type string
207242
Window time.Duration `json:"window" yaml:"window" default:"60s"`
208-
// HTTP
243+
// HTTP is the timeout for the HTTP calls themselves.
244+
//
245+
// required: true
246+
// example: 60s
247+
// swagger:type string
209248
HTTP time.Duration `json:"http" yaml:"http" default:"15s"`
210249
}
211250

0 commit comments

Comments
 (0)