trust.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. package client
  2. import (
  3. "encoding/hex"
  4. "encoding/json"
  5. "errors"
  6. "fmt"
  7. "io"
  8. "net"
  9. "net/http"
  10. "net/url"
  11. "os"
  12. "path"
  13. "path/filepath"
  14. "sort"
  15. "strconv"
  16. "time"
  17. "golang.org/x/net/context"
  18. "github.com/Sirupsen/logrus"
  19. "github.com/docker/distribution/digest"
  20. "github.com/docker/distribution/registry/client/auth"
  21. "github.com/docker/distribution/registry/client/transport"
  22. "github.com/docker/docker/cliconfig"
  23. "github.com/docker/docker/distribution"
  24. "github.com/docker/docker/pkg/jsonmessage"
  25. "github.com/docker/docker/reference"
  26. "github.com/docker/docker/registry"
  27. "github.com/docker/engine-api/types"
  28. registrytypes "github.com/docker/engine-api/types/registry"
  29. "github.com/docker/go-connections/tlsconfig"
  30. "github.com/docker/notary/client"
  31. "github.com/docker/notary/passphrase"
  32. "github.com/docker/notary/trustmanager"
  33. "github.com/docker/notary/trustpinning"
  34. "github.com/docker/notary/tuf/data"
  35. "github.com/docker/notary/tuf/signed"
  36. "github.com/docker/notary/tuf/store"
  37. "github.com/spf13/pflag"
  38. )
  39. var (
  40. releasesRole = path.Join(data.CanonicalTargetsRole, "releases")
  41. untrusted bool
  42. )
  43. // AddTrustedFlags adds content trust flags to the current command flagset
  44. func AddTrustedFlags(fs *pflag.FlagSet, verify bool) {
  45. trusted, message := setupTrustedFlag(verify)
  46. fs.BoolVar(&untrusted, "disable-content-trust", !trusted, message)
  47. }
  48. func setupTrustedFlag(verify bool) (bool, string) {
  49. var trusted bool
  50. if e := os.Getenv("DOCKER_CONTENT_TRUST"); e != "" {
  51. if t, err := strconv.ParseBool(e); t || err != nil {
  52. // treat any other value as true
  53. trusted = true
  54. }
  55. }
  56. message := "Skip image signing"
  57. if verify {
  58. message = "Skip image verification"
  59. }
  60. return trusted, message
  61. }
  62. // IsTrusted returns true if content trust is enabled
  63. func IsTrusted() bool {
  64. return !untrusted
  65. }
  66. type target struct {
  67. reference registry.Reference
  68. digest digest.Digest
  69. size int64
  70. }
  71. func (cli *DockerCli) trustDirectory() string {
  72. return filepath.Join(cliconfig.ConfigDir(), "trust")
  73. }
  74. // certificateDirectory returns the directory containing
  75. // TLS certificates for the given server. An error is
  76. // returned if there was an error parsing the server string.
  77. func (cli *DockerCli) certificateDirectory(server string) (string, error) {
  78. u, err := url.Parse(server)
  79. if err != nil {
  80. return "", err
  81. }
  82. return filepath.Join(cliconfig.ConfigDir(), "tls", u.Host), nil
  83. }
  84. func trustServer(index *registrytypes.IndexInfo) (string, error) {
  85. if s := os.Getenv("DOCKER_CONTENT_TRUST_SERVER"); s != "" {
  86. urlObj, err := url.Parse(s)
  87. if err != nil || urlObj.Scheme != "https" {
  88. return "", fmt.Errorf("valid https URL required for trust server, got %s", s)
  89. }
  90. return s, nil
  91. }
  92. if index.Official {
  93. return registry.NotaryServer, nil
  94. }
  95. return "https://" + index.Name, nil
  96. }
  97. type simpleCredentialStore struct {
  98. auth types.AuthConfig
  99. }
  100. func (scs simpleCredentialStore) Basic(u *url.URL) (string, string) {
  101. return scs.auth.Username, scs.auth.Password
  102. }
  103. func (scs simpleCredentialStore) RefreshToken(u *url.URL, service string) string {
  104. return scs.auth.IdentityToken
  105. }
  106. func (scs simpleCredentialStore) SetRefreshToken(*url.URL, string, string) {
  107. }
  108. // getNotaryRepository returns a NotaryRepository which stores all the
  109. // information needed to operate on a notary repository.
  110. // It creates an HTTP transport providing authentication support.
  111. func (cli *DockerCli) getNotaryRepository(repoInfo *registry.RepositoryInfo, authConfig types.AuthConfig, actions ...string) (*client.NotaryRepository, error) {
  112. server, err := trustServer(repoInfo.Index)
  113. if err != nil {
  114. return nil, err
  115. }
  116. var cfg = tlsconfig.ClientDefault
  117. cfg.InsecureSkipVerify = !repoInfo.Index.Secure
  118. // Get certificate base directory
  119. certDir, err := cli.certificateDirectory(server)
  120. if err != nil {
  121. return nil, err
  122. }
  123. logrus.Debugf("reading certificate directory: %s", certDir)
  124. if err := registry.ReadCertsDirectory(&cfg, certDir); err != nil {
  125. return nil, err
  126. }
  127. base := &http.Transport{
  128. Proxy: http.ProxyFromEnvironment,
  129. Dial: (&net.Dialer{
  130. Timeout: 30 * time.Second,
  131. KeepAlive: 30 * time.Second,
  132. DualStack: true,
  133. }).Dial,
  134. TLSHandshakeTimeout: 10 * time.Second,
  135. TLSClientConfig: &cfg,
  136. DisableKeepAlives: true,
  137. }
  138. // Skip configuration headers since request is not going to Docker daemon
  139. modifiers := registry.DockerHeaders(clientUserAgent(), http.Header{})
  140. authTransport := transport.NewTransport(base, modifiers...)
  141. pingClient := &http.Client{
  142. Transport: authTransport,
  143. Timeout: 5 * time.Second,
  144. }
  145. endpointStr := server + "/v2/"
  146. req, err := http.NewRequest("GET", endpointStr, nil)
  147. if err != nil {
  148. return nil, err
  149. }
  150. challengeManager := auth.NewSimpleChallengeManager()
  151. resp, err := pingClient.Do(req)
  152. if err != nil {
  153. // Ignore error on ping to operate in offline mode
  154. logrus.Debugf("Error pinging notary server %q: %s", endpointStr, err)
  155. } else {
  156. defer resp.Body.Close()
  157. // Add response to the challenge manager to parse out
  158. // authentication header and register authentication method
  159. if err := challengeManager.AddResponse(resp); err != nil {
  160. return nil, err
  161. }
  162. }
  163. creds := simpleCredentialStore{auth: authConfig}
  164. tokenHandler := auth.NewTokenHandler(authTransport, creds, repoInfo.FullName(), actions...)
  165. basicHandler := auth.NewBasicHandler(creds)
  166. modifiers = append(modifiers, transport.RequestModifier(auth.NewAuthorizer(challengeManager, tokenHandler, basicHandler)))
  167. tr := transport.NewTransport(base, modifiers...)
  168. return client.NewNotaryRepository(
  169. cli.trustDirectory(), repoInfo.FullName(), server, tr, cli.getPassphraseRetriever(),
  170. trustpinning.TrustPinConfig{})
  171. }
  172. func convertTarget(t client.Target) (target, error) {
  173. h, ok := t.Hashes["sha256"]
  174. if !ok {
  175. return target{}, errors.New("no valid hash, expecting sha256")
  176. }
  177. return target{
  178. reference: registry.ParseReference(t.Name),
  179. digest: digest.NewDigestFromHex("sha256", hex.EncodeToString(h)),
  180. size: t.Length,
  181. }, nil
  182. }
  183. func (cli *DockerCli) getPassphraseRetriever() passphrase.Retriever {
  184. aliasMap := map[string]string{
  185. "root": "root",
  186. "snapshot": "repository",
  187. "targets": "repository",
  188. "default": "repository",
  189. }
  190. baseRetriever := passphrase.PromptRetrieverWithInOut(cli.in, cli.out, aliasMap)
  191. env := map[string]string{
  192. "root": os.Getenv("DOCKER_CONTENT_TRUST_ROOT_PASSPHRASE"),
  193. "snapshot": os.Getenv("DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE"),
  194. "targets": os.Getenv("DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE"),
  195. "default": os.Getenv("DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE"),
  196. }
  197. return func(keyName string, alias string, createNew bool, numAttempts int) (string, bool, error) {
  198. if v := env[alias]; v != "" {
  199. return v, numAttempts > 1, nil
  200. }
  201. // For non-root roles, we can also try the "default" alias if it is specified
  202. if v := env["default"]; v != "" && alias != data.CanonicalRootRole {
  203. return v, numAttempts > 1, nil
  204. }
  205. return baseRetriever(keyName, alias, createNew, numAttempts)
  206. }
  207. }
  208. // TrustedReference returns the canonical trusted reference for an image reference
  209. func (cli *DockerCli) TrustedReference(ctx context.Context, ref reference.NamedTagged) (reference.Canonical, error) {
  210. repoInfo, err := registry.ParseRepositoryInfo(ref)
  211. if err != nil {
  212. return nil, err
  213. }
  214. // Resolve the Auth config relevant for this server
  215. authConfig := cli.ResolveAuthConfig(ctx, repoInfo.Index)
  216. notaryRepo, err := cli.getNotaryRepository(repoInfo, authConfig, "pull")
  217. if err != nil {
  218. fmt.Fprintf(cli.out, "Error establishing connection to trust repository: %s\n", err)
  219. return nil, err
  220. }
  221. t, err := notaryRepo.GetTargetByName(ref.Tag(), releasesRole, data.CanonicalTargetsRole)
  222. if err != nil {
  223. return nil, err
  224. }
  225. // Only list tags in the top level targets role or the releases delegation role - ignore
  226. // all other delegation roles
  227. if t.Role != releasesRole && t.Role != data.CanonicalTargetsRole {
  228. return nil, notaryError(repoInfo.FullName(), fmt.Errorf("No trust data for %s", ref.Tag()))
  229. }
  230. r, err := convertTarget(t.Target)
  231. if err != nil {
  232. return nil, err
  233. }
  234. return reference.WithDigest(ref, r.digest)
  235. }
  236. // TagTrusted tags a trusted ref
  237. func (cli *DockerCli) TagTrusted(ctx context.Context, trustedRef reference.Canonical, ref reference.NamedTagged) error {
  238. fmt.Fprintf(cli.out, "Tagging %s as %s\n", trustedRef.String(), ref.String())
  239. return cli.client.ImageTag(ctx, trustedRef.String(), ref.String())
  240. }
  241. func notaryError(repoName string, err error) error {
  242. switch err.(type) {
  243. case *json.SyntaxError:
  244. logrus.Debugf("Notary syntax error: %s", err)
  245. return fmt.Errorf("Error: no trust data available for remote repository %s. Try running notary server and setting DOCKER_CONTENT_TRUST_SERVER to its HTTPS address?", repoName)
  246. case signed.ErrExpired:
  247. return fmt.Errorf("Error: remote repository %s out-of-date: %v", repoName, err)
  248. case trustmanager.ErrKeyNotFound:
  249. return fmt.Errorf("Error: signing keys for remote repository %s not found: %v", repoName, err)
  250. case *net.OpError:
  251. return fmt.Errorf("Error: error contacting notary server: %v", err)
  252. case store.ErrMetaNotFound:
  253. return fmt.Errorf("Error: trust data missing for remote repository %s or remote repository not found: %v", repoName, err)
  254. case signed.ErrInvalidKeyType:
  255. return fmt.Errorf("Warning: potential malicious behavior - trust data mismatch for remote repository %s: %v", repoName, err)
  256. case signed.ErrNoKeys:
  257. return fmt.Errorf("Error: could not find signing keys for remote repository %s, or could not decrypt signing key: %v", repoName, err)
  258. case signed.ErrLowVersion:
  259. return fmt.Errorf("Warning: potential malicious behavior - trust data version is lower than expected for remote repository %s: %v", repoName, err)
  260. case signed.ErrRoleThreshold:
  261. return fmt.Errorf("Warning: potential malicious behavior - trust data has insufficient signatures for remote repository %s: %v", repoName, err)
  262. case client.ErrRepositoryNotExist:
  263. return fmt.Errorf("Error: remote trust data does not exist for %s: %v", repoName, err)
  264. case signed.ErrInsufficientSignatures:
  265. return fmt.Errorf("Error: could not produce valid signature for %s. If Yubikey was used, was touch input provided?: %v", repoName, err)
  266. }
  267. return err
  268. }
  269. // TrustedPull handles content trust pulling of an image
  270. func (cli *DockerCli) TrustedPull(ctx context.Context, repoInfo *registry.RepositoryInfo, ref registry.Reference, authConfig types.AuthConfig, requestPrivilege types.RequestPrivilegeFunc) error {
  271. var refs []target
  272. notaryRepo, err := cli.getNotaryRepository(repoInfo, authConfig, "pull")
  273. if err != nil {
  274. fmt.Fprintf(cli.out, "Error establishing connection to trust repository: %s\n", err)
  275. return err
  276. }
  277. if ref.String() == "" {
  278. // List all targets
  279. targets, err := notaryRepo.ListTargets(releasesRole, data.CanonicalTargetsRole)
  280. if err != nil {
  281. return notaryError(repoInfo.FullName(), err)
  282. }
  283. for _, tgt := range targets {
  284. t, err := convertTarget(tgt.Target)
  285. if err != nil {
  286. fmt.Fprintf(cli.out, "Skipping target for %q\n", repoInfo.Name())
  287. continue
  288. }
  289. // Only list tags in the top level targets role or the releases delegation role - ignore
  290. // all other delegation roles
  291. if tgt.Role != releasesRole && tgt.Role != data.CanonicalTargetsRole {
  292. continue
  293. }
  294. refs = append(refs, t)
  295. }
  296. if len(refs) == 0 {
  297. return notaryError(repoInfo.FullName(), fmt.Errorf("No trusted tags for %s", repoInfo.FullName()))
  298. }
  299. } else {
  300. t, err := notaryRepo.GetTargetByName(ref.String(), releasesRole, data.CanonicalTargetsRole)
  301. if err != nil {
  302. return notaryError(repoInfo.FullName(), err)
  303. }
  304. // Only get the tag if it's in the top level targets role or the releases delegation role
  305. // ignore it if it's in any other delegation roles
  306. if t.Role != releasesRole && t.Role != data.CanonicalTargetsRole {
  307. return notaryError(repoInfo.FullName(), fmt.Errorf("No trust data for %s", ref.String()))
  308. }
  309. logrus.Debugf("retrieving target for %s role\n", t.Role)
  310. r, err := convertTarget(t.Target)
  311. if err != nil {
  312. return err
  313. }
  314. refs = append(refs, r)
  315. }
  316. for i, r := range refs {
  317. displayTag := r.reference.String()
  318. if displayTag != "" {
  319. displayTag = ":" + displayTag
  320. }
  321. fmt.Fprintf(cli.out, "Pull (%d of %d): %s%s@%s\n", i+1, len(refs), repoInfo.Name(), displayTag, r.digest)
  322. ref, err := reference.WithDigest(repoInfo, r.digest)
  323. if err != nil {
  324. return err
  325. }
  326. if err := cli.ImagePullPrivileged(ctx, authConfig, ref.String(), requestPrivilege, false); err != nil {
  327. return err
  328. }
  329. // If reference is not trusted, tag by trusted reference
  330. if !r.reference.HasDigest() {
  331. tagged, err := reference.WithTag(repoInfo, r.reference.String())
  332. if err != nil {
  333. return err
  334. }
  335. trustedRef, err := reference.WithDigest(repoInfo, r.digest)
  336. if err != nil {
  337. return err
  338. }
  339. if err := cli.TagTrusted(ctx, trustedRef, tagged); err != nil {
  340. return err
  341. }
  342. }
  343. }
  344. return nil
  345. }
  346. // TrustedPush handles content trust pushing of an image
  347. func (cli *DockerCli) TrustedPush(ctx context.Context, repoInfo *registry.RepositoryInfo, ref reference.Named, authConfig types.AuthConfig, requestPrivilege types.RequestPrivilegeFunc) error {
  348. responseBody, err := cli.ImagePushPrivileged(ctx, authConfig, ref.String(), requestPrivilege)
  349. if err != nil {
  350. return err
  351. }
  352. defer responseBody.Close()
  353. // If it is a trusted push we would like to find the target entry which match the
  354. // tag provided in the function and then do an AddTarget later.
  355. target := &client.Target{}
  356. // Count the times of calling for handleTarget,
  357. // if it is called more that once, that should be considered an error in a trusted push.
  358. cnt := 0
  359. handleTarget := func(aux *json.RawMessage) {
  360. cnt++
  361. if cnt > 1 {
  362. // handleTarget should only be called one. This will be treated as an error.
  363. return
  364. }
  365. var pushResult distribution.PushResult
  366. err := json.Unmarshal(*aux, &pushResult)
  367. if err == nil && pushResult.Tag != "" && pushResult.Digest.Validate() == nil {
  368. h, err := hex.DecodeString(pushResult.Digest.Hex())
  369. if err != nil {
  370. target = nil
  371. return
  372. }
  373. target.Name = registry.ParseReference(pushResult.Tag).String()
  374. target.Hashes = data.Hashes{string(pushResult.Digest.Algorithm()): h}
  375. target.Length = int64(pushResult.Size)
  376. }
  377. }
  378. var tag string
  379. switch x := ref.(type) {
  380. case reference.Canonical:
  381. return errors.New("cannot push a digest reference")
  382. case reference.NamedTagged:
  383. tag = x.Tag()
  384. }
  385. // We want trust signatures to always take an explicit tag,
  386. // otherwise it will act as an untrusted push.
  387. if tag == "" {
  388. if err = jsonmessage.DisplayJSONMessagesStream(responseBody, cli.out, cli.outFd, cli.isTerminalOut, nil); err != nil {
  389. return err
  390. }
  391. fmt.Fprintln(cli.out, "No tag specified, skipping trust metadata push")
  392. return nil
  393. }
  394. if err = jsonmessage.DisplayJSONMessagesStream(responseBody, cli.out, cli.outFd, cli.isTerminalOut, handleTarget); err != nil {
  395. return err
  396. }
  397. if cnt > 1 {
  398. return fmt.Errorf("internal error: only one call to handleTarget expected")
  399. }
  400. if target == nil {
  401. fmt.Fprintln(cli.out, "No targets found, please provide a specific tag in order to sign it")
  402. return nil
  403. }
  404. fmt.Fprintln(cli.out, "Signing and pushing trust metadata")
  405. repo, err := cli.getNotaryRepository(repoInfo, authConfig, "push", "pull")
  406. if err != nil {
  407. fmt.Fprintf(cli.out, "Error establishing connection to notary repository: %s\n", err)
  408. return err
  409. }
  410. // get the latest repository metadata so we can figure out which roles to sign
  411. err = repo.Update(false)
  412. switch err.(type) {
  413. case client.ErrRepoNotInitialized, client.ErrRepositoryNotExist:
  414. keys := repo.CryptoService.ListKeys(data.CanonicalRootRole)
  415. var rootKeyID string
  416. // always select the first root key
  417. if len(keys) > 0 {
  418. sort.Strings(keys)
  419. rootKeyID = keys[0]
  420. } else {
  421. rootPublicKey, err := repo.CryptoService.Create(data.CanonicalRootRole, "", data.ECDSAKey)
  422. if err != nil {
  423. return err
  424. }
  425. rootKeyID = rootPublicKey.ID()
  426. }
  427. // Initialize the notary repository with a remotely managed snapshot key
  428. if err := repo.Initialize(rootKeyID, data.CanonicalSnapshotRole); err != nil {
  429. return notaryError(repoInfo.FullName(), err)
  430. }
  431. fmt.Fprintf(cli.out, "Finished initializing %q\n", repoInfo.FullName())
  432. err = repo.AddTarget(target, data.CanonicalTargetsRole)
  433. case nil:
  434. // already initialized and we have successfully downloaded the latest metadata
  435. err = cli.addTargetToAllSignableRoles(repo, target)
  436. default:
  437. return notaryError(repoInfo.FullName(), err)
  438. }
  439. if err == nil {
  440. err = repo.Publish()
  441. }
  442. if err != nil {
  443. fmt.Fprintf(cli.out, "Failed to sign %q:%s - %s\n", repoInfo.FullName(), tag, err.Error())
  444. return notaryError(repoInfo.FullName(), err)
  445. }
  446. fmt.Fprintf(cli.out, "Successfully signed %q:%s\n", repoInfo.FullName(), tag)
  447. return nil
  448. }
  449. // Attempt to add the image target to all the top level delegation roles we can
  450. // (based on whether we have the signing key and whether the role's path allows
  451. // us to).
  452. // If there are no delegation roles, we add to the targets role.
  453. func (cli *DockerCli) addTargetToAllSignableRoles(repo *client.NotaryRepository, target *client.Target) error {
  454. var signableRoles []string
  455. // translate the full key names, which includes the GUN, into just the key IDs
  456. allCanonicalKeyIDs := make(map[string]struct{})
  457. for fullKeyID := range repo.CryptoService.ListAllKeys() {
  458. allCanonicalKeyIDs[path.Base(fullKeyID)] = struct{}{}
  459. }
  460. allDelegationRoles, err := repo.GetDelegationRoles()
  461. if err != nil {
  462. return err
  463. }
  464. // if there are no delegation roles, then just try to sign it into the targets role
  465. if len(allDelegationRoles) == 0 {
  466. return repo.AddTarget(target, data.CanonicalTargetsRole)
  467. }
  468. // there are delegation roles, find every delegation role we have a key for, and
  469. // attempt to sign into into all those roles.
  470. for _, delegationRole := range allDelegationRoles {
  471. // We do not support signing any delegation role that isn't a direct child of the targets role.
  472. // Also don't bother checking the keys if we can't add the target
  473. // to this role due to path restrictions
  474. if path.Dir(delegationRole.Name) != data.CanonicalTargetsRole || !delegationRole.CheckPaths(target.Name) {
  475. continue
  476. }
  477. for _, canonicalKeyID := range delegationRole.KeyIDs {
  478. if _, ok := allCanonicalKeyIDs[canonicalKeyID]; ok {
  479. signableRoles = append(signableRoles, delegationRole.Name)
  480. break
  481. }
  482. }
  483. }
  484. if len(signableRoles) == 0 {
  485. return fmt.Errorf("no valid signing keys for delegation roles")
  486. }
  487. return repo.AddTarget(target, signableRoles...)
  488. }
  489. // ImagePullPrivileged pulls the image and displays it to the output
  490. func (cli *DockerCli) ImagePullPrivileged(ctx context.Context, authConfig types.AuthConfig, ref string, requestPrivilege types.RequestPrivilegeFunc, all bool) error {
  491. encodedAuth, err := EncodeAuthToBase64(authConfig)
  492. if err != nil {
  493. return err
  494. }
  495. options := types.ImagePullOptions{
  496. RegistryAuth: encodedAuth,
  497. PrivilegeFunc: requestPrivilege,
  498. All: all,
  499. }
  500. responseBody, err := cli.client.ImagePull(ctx, ref, options)
  501. if err != nil {
  502. return err
  503. }
  504. defer responseBody.Close()
  505. return jsonmessage.DisplayJSONMessagesStream(responseBody, cli.out, cli.outFd, cli.isTerminalOut, nil)
  506. }
  507. // ImagePushPrivileged push the image
  508. func (cli *DockerCli) ImagePushPrivileged(ctx context.Context, authConfig types.AuthConfig, ref string, requestPrivilege types.RequestPrivilegeFunc) (io.ReadCloser, error) {
  509. encodedAuth, err := EncodeAuthToBase64(authConfig)
  510. if err != nil {
  511. return nil, err
  512. }
  513. options := types.ImagePushOptions{
  514. RegistryAuth: encodedAuth,
  515. PrivilegeFunc: requestPrivilege,
  516. }
  517. return cli.client.ImagePush(ctx, ref, options)
  518. }