forked from containers/podman
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This endpoint just validates credentials: https://github.com/moby/moby/blob/v20.10.4/api/swagger.yaml#L7936-L7977 Fixes: containers#9564 Signed-off-by: troyready <[email protected]>
- Loading branch information
Showing
5 changed files
with
104 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package compat | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"strings" | ||
|
||
DockerClient "github.com/containers/image/v5/docker" | ||
"github.com/containers/image/v5/types" | ||
"github.com/containers/podman/v3/pkg/api/handlers/utils" | ||
"github.com/containers/podman/v3/pkg/domain/entities" | ||
"github.com/containers/podman/v3/pkg/registries" | ||
docker "github.com/docker/docker/api/types" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func Auth(w http.ResponseWriter, r *http.Request) { | ||
var authConfig docker.AuthConfig | ||
err := json.NewDecoder(r.Body).Decode(&authConfig) | ||
if err != nil { | ||
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrapf(err, "failed to parse request")) | ||
return | ||
} | ||
|
||
skipTLS := types.NewOptionalBool(false) | ||
if strings.HasPrefix(authConfig.ServerAddress, "http://localhost/") || strings.HasPrefix(authConfig.ServerAddress, "http://localhost:") { | ||
// support for local testing | ||
skipTLS = types.NewOptionalBool(true) | ||
} | ||
|
||
fmt.Println("Authenticating with existing credentials...") | ||
sysCtx := types.SystemContext{ | ||
AuthFilePath: "", | ||
DockerCertPath: "", | ||
DockerInsecureSkipTLSVerify: skipTLS, | ||
SystemRegistriesConfPath: registries.SystemRegistriesConfPath(), | ||
} | ||
if err := DockerClient.CheckAuth(context.Background(), &sysCtx, authConfig.Username, authConfig.Password, authConfig.ServerAddress); err == nil { | ||
utils.WriteResponse(w, http.StatusOK, entities.AuthReport{ | ||
IdentityToken: "", | ||
Status: "Login Succeeded", | ||
}) | ||
} else { | ||
utils.WriteResponse(w, http.StatusBadRequest, entities.AuthReport{ | ||
IdentityToken: "", | ||
Status: "login attempt to " + authConfig.ServerAddress + " failed with status: " + err.Error(), | ||
}) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,13 +1,33 @@ | ||
package server | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/containers/podman/v3/pkg/api/handlers/compat" | ||
"github.com/gorilla/mux" | ||
) | ||
|
||
func (s *APIServer) registerAuthHandlers(r *mux.Router) error { | ||
r.Handle(VersionedPath("/auth"), s.APIHandler(compat.UnsupportedHandler)) | ||
// swagger:operation POST /auth compat auth | ||
// --- | ||
// summary: Check auth configuration | ||
// tags: | ||
// - system (compat) | ||
// produces: | ||
// - application/json | ||
// parameters: | ||
// - in: body | ||
// name: authConfig | ||
// description: Authentication to check | ||
// schema: | ||
// $ref: "#/definitions/AuthConfig" | ||
// responses: | ||
// 200: | ||
// $ref: "#/responses/SystemAuthResponse" | ||
// 500: | ||
// $ref: "#/responses/InternalError" | ||
r.Handle(VersionedPath("/auth"), s.APIHandler(compat.Auth)).Methods(http.MethodPost) | ||
// Added non version path to URI to support docker non versioned paths | ||
r.Handle("/auth", s.APIHandler(compat.UnsupportedHandler)) | ||
r.Handle("/auth", s.APIHandler(compat.Auth)).Methods(http.MethodPost) | ||
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
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