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
3838type 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
170167func 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 ... )
0 commit comments