GoogleContainerTools / jib

🏗 Build container images for your Java applications.
Apache License 2.0
13.69k stars 1.44k forks source link

jib build 401 but docker works #3955

Closed wenerme closed 8 months ago

wenerme commented 1 year ago

Environment:

Description of the issue:

jib:build failed with 401, but jib:dockerBuild works.

Expected behavior:

jib:build works

Steps to reproduce:

  1. just jib:build

jib-maven-plugin Configuration:

                <plugin>
                    <groupId>com.google.cloud.tools</groupId>
                    <artifactId>jib-maven-plugin</artifactId>
                    <version>3.3.1</version>
                    <configuration>
                        <from>
                            <image>wener/java:8</image>
                            <platforms>
                                <!--
                                <platform>
                                    <architecture>amd64</architecture>
                                    <os>linux</os>
                                </platform>
                                -->
                                <platform>
                                    <architecture>arm64</architecture>
                                    <os>linux</os>
                                </platform>
                            </platforms>
                        </from>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>io.github.zlika</groupId>
                    <artifactId>reproducible-build-maven-plugin</artifactId>
                    <version>0.16</version>
                </plugin>

Log output:

[INFO] Getting manifest for base image wener/java:8...
[INFO] Building dependencies layer...
[INFO] Building resources layer...
[INFO] Building classes layer...
[INFO] Building jvm arg files layer...
[INFO] Using credentials from Docker config (~/.config/containers/auth.json) for A/D/C-docker/B-cloud-plus-B-gateway:a301aa6
[INFO] The base image requires auth. Trying again for wener/java:8...
[INFO] Using base image with digest: sha256:259926a6f245af1410572445c5fb7ebff9901569ed58b8f0e302f92b59df75e4
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  13.058 s
[INFO] Finished at: 2023-03-12T15:59:46+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.google.cloud.tools:jib-maven-plugin:3.3.1:build (default-cli) on project B-gateway: Build image failed, perhaps you should make sure your credentials for 'A/D/C-docker/B-cloud-plus-B-gateway' are set up correctly. See https://github.com/GoogleContainerTools/jib/blob/master/docs/faq.md#what-should-i-do-when-the-registry-responds-with-unauthorized for help: Unauthorized for A/D/C-docker/B-cloud-plus-B-gateway: 401 Unauthorized
[ERROR] POST https://A/v2/D/C-docker/B-cloud-plus-B-gateway/blobs/uploads/
[ERROR] {"errors":[{"code":"UNAUTHORIZED","message":"authentication required","detail":[{"Type":"repository","Class":"","Name":"D/C-docker/B-cloud-plus-B-gateway","Action":"pull"},{"Type":"repository","Class":"","Name":"D/C-docker/B-cloud-plus-B-gateway","Action":"push"}]}]}

Additional Information:

crane & docker works

crane copy wener/java:8 A/D/C-docker/wener-java:
crane copy wener/java:8 A/D/C-docker/wener-java:8
2023/03/12 16:01:04 Copying from wener/java:8 to A/D/C-docker/wener-java:8
2023/03/12 16:01:08 retrying without mount: POST https://A/v2/D/C-docker/wener-java/blobs/uploads/?from=wener%2Fjava&mount=sha256%3A55bd82c43e338de5521f7d5470ca6c41e97421de9a3e112fa62cc77c07bee071&origin=REDACTED: BAD_REQUEST: invalid docker repository
2023/03/12 16:01:10 pushed blob: sha256:65128ce67b4586a845793f301ca8607899fcd98485a79244a1ad52444d1b02f1
...

~/.docker/config.json only contain

{
    "auths": {
        "A": {
            "auth": "xxxxx=="
        }
    }
}

also tried jib.to.password & username, still 401

But multi arch image can only build by jib:build.

mpeddada1 commented 1 year ago

@wenerme thanks for the question, you may find this section in the FAQ to be helpful when troubleshooting the Unauthorized error message that you're currently seeing.

wenerme commented 1 year ago

jib works good with docker.io, but when using registry from https://coding.net/, the push will fail, seem like compatibility issus,

when password not right the error is

[ERROR] Failed to execute goal com.google.cloud.tools:jib-maven-plugin:3.3.1:build (default-cli) on project demo-app: Build image failed, perhaps you should make sure your credentials for 'zhensi-docker.pkg.coding.net/core/core/demo-app' are set up correctly. See https://github.com/GoogleContainerTools/jib/blob/master/docs/faq.md#what-should-i-do-when-the-registry-responds-with-unauthorized for help: Unauthorized for zhensi-docker.pkg.coding.net/core/core/demo-app: 401 Unauthorized
[ERROR] GET https://auth.pkg.coding.net/artifacts-auth/docker/jwt?host=zhensi-docker.pkg.coding.net?service%3Ddocker&scope=repository:core/core/demo-app:pull,push
[ERROR] {"errors":[{"code":"UNAUTHORIZED","message":"Invalid credential. 请确认输入了正确的用户名和密码。\n"}]}

When password is right the error is

[ERROR] Failed to execute goal com.google.cloud.tools:jib-maven-plugin:3.3.1:build (default-cli) on project demo-app: Build image failed, perhaps you should make sure your credentials for 'zhensi-docker.pkg.coding.net/core/core/demo-app' are set up correctly. See https://github.com/GoogleContainerTools/jib/blob/master/docs/faq.md#what-should-i-do-when-the-registry-responds-with-unauthorized for help: Unauthorized for zhensi-docker.pkg.coding.net/core/core/demo-app: 401 Unauthorized
[ERROR] POST https://zhensi-docker.pkg.coding.net/v2/core/core/demo-app/blobs/uploads/
[ERROR] {"errors":[{"code":"UNAUTHORIZED","message":"authentication required","detail":[{"Type":"repository","Class":"","Name":"core/core/demo-app","Action":"pull"},{"Type":"repository","Class":"","Name":"core/core/demo-app","Action":"push"}]}]}

@mpeddada1 I can pm you the username & password.

LQfly commented 1 year ago

@wenerme do you solve it ?

wenerme commented 1 year ago

@LQfly Maybe the problem is related to coding.net, I changed to gitea, works as expected.

burkedavison commented 8 months ago

Closing based on OP feedback.