Basicauth giving error illegal base64

1. Caddy version (caddy version):

version 2.3.0

2. How I run Caddy:

a. System environment:

Raspberry Pi, Docker 19.03.13
Caddy I administrate in Portainer.

b. Command:

caddy reload

c. Service/unit/compose file:

{
    "AppArmorProfile": "",
    "Args": [
        "run",
        "--config",
        "/config/Caddyfile",
        "--adapter",
        "caddyfile"
    ],
    "Config": {
        "AttachStderr": false,
        "AttachStdin": false,
        "AttachStdout": false,
        "Cmd": [
            "caddy",
            "run",
            "--config",
            "/config/Caddyfile",
            "--adapter",
            "caddyfile"
        ],
        "Domainname": "",
        "Entrypoint": null,
        "Env": [
            "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
            "CADDY_VERSION=v2.3.0",
            "XDG_CONFIG_HOME=/config",
            "XDG_DATA_HOME=/data"
        ],
        "ExposedPorts": {
            "2019/tcp": {},
            "443/tcp": {},
            "80/tcp": {}
        },
        "Hostname": "d70063c8960d",
        "Image": "caddy:latest",
        "Labels": {
            "org.opencontainers.image.description": "a powerful, enterprise-ready, open source web server with automatic HTTPS written in Go",
            "org.opencontainers.image.documentation": "https://caddyserver.com/docs",
            "org.opencontainers.image.licenses": "Apache-2.0",
            "org.opencontainers.image.source": "https://github.com/caddyserver/caddy-docker",
            "org.opencontainers.image.title": "Caddy",
            "org.opencontainers.image.url": "https://caddyserver.com",
            "org.opencontainers.image.vendor": "Light Code Labs",
            "org.opencontainers.image.version": "v2.3.0"
        },
        "OnBuild": null,
        "OpenStdin": false,
        "StdinOnce": false,
        "Tty": false,
        "User": "",
        "Volumes": {
            "/config": {},
            "/data": {},
            "/srv": {}
        },
        "WorkingDir": "/srv"
    },
    "Created": "2021-04-04T11:33:47.600143609Z",
    "Driver": "overlay2",
    "ExecIDs": [
        "088f3b6853688b75d7a79d4527e4a52eb91b00b866708fe5500f6f23514e9c7d",
        "aaf42a433b8f6f6ea5f9aed94c59d8963fc698b23622d18e522f3ad6ec44a350"
    ],
    "GraphDriver": {
        "Data": {
            "LowerDir": "/var/lib/docker/overlay2/8edbba660571ab1622059aba3a4c1ca9998250a5b7f72a836fa466ec8246d5db-init/diff:/var/lib/docker/overlay2/0965fe3fdd29232a3461f35e742b85b12a7132cb331113b721884f25abde2f7f/diff:/var/lib/docker/overlay2/7828abb91200ff5278f2eced68dcfaa6a99ab5c8b4b16bb4663b315ae0842b13/diff:/var/lib/docker/overlay2/ea1fed0ef2acf04648c652f871daba758c5ab342f74547c810c39807a65b1748/diff:/var/lib/docker/overlay2/08f14ad14bd81543eb3e36bce4cb424c5e65a2ffb1f4bb58a6d8481b26acda98/diff:/var/lib/docker/overlay2/f46e2814a7bb3f699f6bb5242d637cd4251415b258b96bd734922c4f83af8487/diff",
            "MergedDir": "/var/lib/docker/overlay2/8edbba660571ab1622059aba3a4c1ca9998250a5b7f72a836fa466ec8246d5db/merged",
            "UpperDir": "/var/lib/docker/overlay2/8edbba660571ab1622059aba3a4c1ca9998250a5b7f72a836fa466ec8246d5db/diff",
            "WorkDir": "/var/lib/docker/overlay2/8edbba660571ab1622059aba3a4c1ca9998250a5b7f72a836fa466ec8246d5db/work"
        },
        "Name": "overlay2"
    },
    "HostConfig": {
        "AutoRemove": false,
        "Binds": [
            "/home/pi/docker/caddy-prod-01/srv:/srv",
            "/home/pi/docker/caddy-prod-01/data:/data",
            "/home/pi/docker/caddy-prod-01/config:/config"
        ],
        "BlkioDeviceReadBps": null,
        "BlkioDeviceReadIOps": null,
        "BlkioDeviceWriteBps": null,
        "BlkioDeviceWriteIOps": null,
        "BlkioWeight": 0,
        "BlkioWeightDevice": [],
        "CapAdd": [
            "AUDIT_WRITE",
            "CHOWN",
            "DAC_OVERRIDE",
            "FOWNER",
            "FSETID",
            "KILL",
            "MKNOD",
            "NET_BIND_SERVICE",
            "NET_RAW",
            "SETFCAP",
            "SETGID",
            "SETPCAP",
            "SETUID",
            "SYS_CHROOT"
        ],
        "CapDrop": [
            "AUDIT_CONTROL",
            "BLOCK_SUSPEND",
            "DAC_READ_SEARCH",
            "IPC_LOCK",
            "IPC_OWNER",
            "LEASE",
            "LINUX_IMMUTABLE",
            "MAC_ADMIN",
            "MAC_OVERRIDE",
            "NET_ADMIN",
            "NET_BROADCAST",
            "SYSLOG",
            "SYS_ADMIN",
            "SYS_BOOT",
            "SYS_MODULE",
            "SYS_NICE",
            "SYS_PACCT",
            "SYS_PTRACE",
            "SYS_RAWIO",
            "SYS_RESOURCE",
            "SYS_TIME",
            "SYS_TTY_CONFIG",
            "WAKE_ALARM"
        ],
        "Capabilities": null,
        "Cgroup": "",
        "CgroupParent": "",
        "ConsoleSize": [
            0,
            0
        ],
        "ContainerIDFile": "",
        "CpuCount": 0,
        "CpuPercent": 0,
        "CpuPeriod": 0,
        "CpuQuota": 0,
        "CpuRealtimePeriod": 0,
        "CpuRealtimeRuntime": 0,
        "CpuShares": 0,
        "CpusetCpus": "",
        "CpusetMems": "",
        "DeviceCgroupRules": null,
        "DeviceRequests": null,
        "Devices": [],
        "Dns": [],
        "DnsOptions": [],
        "DnsSearch": [],
        "ExtraHosts": [],
        "GroupAdd": null,
        "IOMaximumBandwidth": 0,
        "IOMaximumIOps": 0,
        "IpcMode": "private",
        "Isolation": "",
        "KernelMemory": 0,
        "KernelMemoryTCP": 0,
        "Links": null,
        "LogConfig": {
            "Config": {},
            "Type": "json-file"
        },
        "MaskedPaths": [
            "/proc/asound",
            "/proc/acpi",
            "/proc/kcore",
            "/proc/keys",
            "/proc/latency_stats",
            "/proc/timer_list",
            "/proc/timer_stats",
            "/proc/sched_debug",
            "/proc/scsi",
            "/sys/firmware"
        ],
        "Memory": 0,
        "MemoryReservation": 0,
        "MemorySwap": 0,
        "MemorySwappiness": null,
        "NanoCpus": 0,
        "NetworkMode": "host",
        "OomKillDisable": null,
        "OomScoreAdj": 0,
        "PidMode": "",
        "PidsLimit": null,
        "PortBindings": {},
        "Privileged": false,
        "PublishAllPorts": false,
        "ReadonlyPaths": [
            "/proc/bus",
            "/proc/fs",
            "/proc/irq",
            "/proc/sys",
            "/proc/sysrq-trigger"
        ],
        "ReadonlyRootfs": false,
        "RestartPolicy": {
            "MaximumRetryCount": 0,
            "Name": "no"
        },
        "Runtime": "runc",
        "SecurityOpt": null,
        "ShmSize": 67108864,
        "UTSMode": "",
        "Ulimits": null,
        "UsernsMode": "",
        "VolumeDriver": "",
        "VolumesFrom": null
    },
    "HostnamePath": "/var/lib/docker/containers/cb34068c7a8e225a2de9e433bcd8bc85a7cef56c50555173d0e5e69d4adc86f4/hostname",
    "HostsPath": "/var/lib/docker/containers/cb34068c7a8e225a2de9e433bcd8bc85a7cef56c50555173d0e5e69d4adc86f4/hosts",
    "Id": "cb34068c7a8e225a2de9e433bcd8bc85a7cef56c50555173d0e5e69d4adc86f4",
    "Image": "sha256:42db38da968682707e6cf0fabb16f93770388907d8a208fca0db74cae3183ba2",
    "LogPath": "/var/lib/docker/containers/cb34068c7a8e225a2de9e433bcd8bc85a7cef56c50555173d0e5e69d4adc86f4/cb34068c7a8e225a2de9e433bcd8bc85a7cef56c50555173d0e5e69d4adc86f4-json.log",
    "MountLabel": "",
    "Mounts": [
        {
            "Destination": "/srv",
            "Mode": "",
            "Propagation": "rprivate",
            "RW": true,
            "Source": "/home/pi/docker/caddy-prod-01/srv",
            "Type": "bind"
        },
        {
            "Destination": "/data",
            "Mode": "",
            "Propagation": "rprivate",
            "RW": true,
            "Source": "/home/pi/docker/caddy-prod-01/data",
            "Type": "bind"
        },
        {
            "Destination": "/config",
            "Mode": "",
            "Propagation": "rprivate",
            "RW": true,
            "Source": "/home/pi/docker/caddy-prod-01/config",
            "Type": "bind"
        }
    ],
    "Name": "/caddy_test_01",
    "NetworkSettings": {
        "Bridge": "",
        "EndpointID": "",
        "Gateway": "",
        "GlobalIPv6Address": "",
        "GlobalIPv6PrefixLen": 0,
        "HairpinMode": false,
        "IPAddress": "",
        "IPPrefixLen": 0,
        "IPv6Gateway": "",
        "LinkLocalIPv6Address": "",
        "LinkLocalIPv6PrefixLen": 0,
        "MacAddress": "",
        "Networks": {
            "host": {
                "Aliases": null,
                "DriverOpts": null,
                "EndpointID": "73e53b9219ee8b148f033ba26b0fd8b418c6ef76e473417ed54885be239f2e59",
                "Gateway": "",
                "GlobalIPv6Address": "",
                "GlobalIPv6PrefixLen": 0,
                "IPAMConfig": {},
                "IPAddress": "",
                "IPPrefixLen": 0,
                "IPv6Gateway": "",
                "Links": null,
                "MacAddress": "",
                "NetworkID": "5c689c02a96ba7da1d82b8150074279020e3fa92fac352dcb5ca331e01169eb8"
            }
        },
        "Ports": {},
        "SandboxID": "b78cb93b04f2feb1a5cccf6751a75ffb56c471514147610021330704742aadd0",
        "SandboxKey": "/var/run/docker/netns/default",
        "SecondaryIPAddresses": null,
        "SecondaryIPv6Addresses": null
    },
    "Path": "caddy",
    "Platform": "linux",
    "Portainer": {
        "ResourceControl": {
            "Id": 43,
            "ResourceId": "cb34068c7a8e225a2de9e433bcd8bc85a7cef56c50555173d0e5e69d4adc86f4",
            "SubResourceIds": [],
            "Type": 1,
            "UserAccesses": [],
            "TeamAccesses": [],
            "Public": false,
            "AdministratorsOnly": true,
            "System": false
        }
    },
    "ProcessLabel": "",
    "ResolvConfPath": "/var/lib/docker/containers/cb34068c7a8e225a2de9e433bcd8bc85a7cef56c50555173d0e5e69d4adc86f4/resolv.conf",
    "RestartCount": 0,
    "State": {
        "Dead": false,
        "Error": "",
        "ExitCode": 0,
        "FinishedAt": "2021-04-14T17:01:55.083064722Z",
        "OOMKilled": false,
        "Paused": false,
        "Pid": 26214,
        "Restarting": false,
        "Running": true,
        "StartedAt": "2021-04-14T17:01:56.149599327Z",
        "Status": "running"
    }
}

d. My complete Caddyfile or JSON config:

rr11.duckdns.org {
        reverse_proxy /ui/* 192.168.2.61:1880
}

192.168.2.62 {
        root * /srv
        # Nodered Dashboard under /ui/
        reverse_proxy /ui/* 192.168.2.61:1880
        basicauth / { maggi JDJhJDE0JE93ek5Td2RCc3JhLzhVZ1RhUDJmMmVFL3BWQi5hTFd2cnBJOHJWQTJFbzV2d0pDUXhUaEtL }

        # lägga till portainer där  inkommande är /portainer/
        handle /portainer/* {
                uri replace /portainer/ /
                reverse_proxy 192.168.2.62:9000
        }
        # leverera html
        file_server
}

3. The problem I’m having:

basicauth gives a error message, se below. Everything except basicauth is working just fine.

4. Error messages and/or full log output:

/config # caddy reload
2021/04/16 08:29:17.995 INFO using adjacent Caddyfile
reload: sending configuration to instance: caddy responded with error: HTTP 400: {“error”:“loading config: loading new config: loading http app module: provision http: server srv0: setting up route handlers: route 1: loading handler modules: position 0: loading module ‘subroute’: provision http.handlers.subroute: setting up subroutes: route 1: loading handler modules: position 0: loading module ‘authentication’: provision http.handlers.authentication: loading authentication providers: module name ‘http_basic’: provision http.authentication.providers.http_basic: base64-decoding password: illegal base64 data at input byte 4”}

5. What I already tried:

I tried:

  1. changing the path in after basicauth to / or * or /ui/ - all give the same error
  2. copied the exact texts and example from example page on basicauth, still the same error
  3. Recreate the caddy container couple of times

6. Links to relevant resources:

Whitespace is significant in the Caddyfile, you must use newlines after { and before }.

What’s happening is Caddy is parsing the } as being the optional salt parameter (which you don’t need for bcrypt passwords), and it tries to decode that as base64.

Also, your basicauth matcher of / only matches requests to exactly / and nothing else, so you probably want to remove the / so that the rest of the paths are also protected.

Here, use handle_path instead of handle, and you can remove uri replace. The handle_path directive has built-in path prefix stripping logic.

Thank you very much @francislavoie. That solved it! I guess being a newbie is always a challenge. I´ll use the hande_path directive as well.
Regards and happy weekend
Magnus

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.