mirror of
https://github.com/containers/podman.git
synced 2026-07-29 08:26:45 -04:00
* Support the `X-Registry-Auth` http-request header. * The content of the header is a base64 encoded JSON payload which can either be a single auth config or a map of auth configs (user+pw or token) with the corresponding registries being the keys. Vanilla Docker, projectatomic Docker and the bindings are transparantly supported. * Add a hidden `--registries-conf` flag. Buildah exposes the same flag, mostly for testing purposes. * Do all credential parsing in the client (i.e., `cmd/podman`) pass the username and password in the backend instead of unparsed credentials. * Add a `pkg/auth` which handles most of the heavy lifting. * Go through the authentication-handling code of most commands, bindings and endpoints. Migrate them to the new code and fix issues as seen. A final evaluation and more tests is still required *after* this change. * The manifest-push endpoint is missing certain parameters and should use the ABI function instead. Adding auth-support isn't really possible without these parts working. * The container commands and endpoints (i.e., create and run) have not been changed yet. The APIs don't yet account for the authfile. * Add authentication tests to `pkg/bindings`. Fixes: #6384 Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
72 lines
1.9 KiB
Go
72 lines
1.9 KiB
Go
package containers
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/containers/libpod/libpod/define"
|
|
"github.com/containers/libpod/pkg/api/handlers"
|
|
"github.com/containers/libpod/pkg/bindings"
|
|
jsoniter "github.com/json-iterator/go"
|
|
"github.com/pkg/errors"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
|
|
|
// ExecCreate creates a new exec session in an existing container.
|
|
// The exec session will not be started; that is done with ExecStart.
|
|
// Returns ID of new exec session, or an error if one occurred.
|
|
func ExecCreate(ctx context.Context, nameOrID string, config *handlers.ExecCreateConfig) (string, error) {
|
|
conn, err := bindings.GetClient(ctx)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
if config == nil {
|
|
return "", errors.Errorf("must provide a configuration for exec session")
|
|
}
|
|
|
|
requestJSON, err := json.Marshal(config)
|
|
if err != nil {
|
|
return "", errors.Wrapf(err, "error marshalling exec config to JSON")
|
|
}
|
|
jsonReader := strings.NewReader(string(requestJSON))
|
|
|
|
resp, err := conn.DoRequest(jsonReader, http.MethodPost, "/containers/%s/exec", nil, nil, nameOrID)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
respStruct := new(handlers.ExecCreateResponse)
|
|
if err := resp.Process(respStruct); err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return respStruct.ID, nil
|
|
}
|
|
|
|
// ExecInspect inspects an existing exec session, returning detailed information
|
|
// about it.
|
|
func ExecInspect(ctx context.Context, sessionID string) (*define.InspectExecSession, error) {
|
|
conn, err := bindings.GetClient(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
logrus.Debugf("Inspecting session ID %q", sessionID)
|
|
|
|
resp, err := conn.DoRequest(nil, http.MethodGet, "/exec/%s/json", nil, nil, sessionID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
respStruct := new(define.InspectExecSession)
|
|
if err := resp.Process(respStruct); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return respStruct, nil
|
|
}
|