Skip to content

Somehow... Fresh install broke after bringing container down and back up. Encryption key related. #4554

Closed

Description

@Hallsie

Fresh install:

Clone the master git
Change needed values in the docker-compose.yml:
ports: 9000
ALLOWED_HOSTNAMES=[the ones I need]
Timezone: America/New_York
Force https: true

First Issue the readme file says to change the FORCE_HTTPS=false to FORCE_HTTPS=1 That does not work.

So I'm doing this because I'm putting this behind my own NPM setup. Everything is set up there. I get everything working there. We look good. I change my employee information. I setup a customer. I create an item. I make a sale to my customer. All is well.

I attempt to setup email. SMTP set for my gmail account I want to use. Everything is setup the way google tells me to set it up. Error on the screen when I say to send the receipt via email. Look for logs, nothing. I bring down the container and bring it back up just in case something needed to refresh or who knows what and boom, anywhere that I had information: mostly customers, items, and sales all get an error.

I moved to development so I could see the error and it is related to this:
SYSTEMPATH/Encryption/Encryption.php at line 133

126 }
127
128 if (! in_array($this->driver, $this->drivers, true)) {
129 throw EncryptionException::forUnKnownHandler($this->driver);
130 }
131
132 if (empty($this->key)) {
133 throw EncryptionException::forNeedsStarterKey();
134 }
135
136 $this->hmacKey = bin2hex(\hash_hkdf($this->digest, $this->key));
137
138 $handlerName = 'CodeIgniter\Encryption\Handlers\' . $this->driver . 'Handler';
139 $this->encrypter = new $handlerName($config);
140

I have been troubleshooting with ChatGPT to try to find what is not working or what may be missing and so far I have created a key and everything can see the key but the key does not seem to be coming into the /app/.env where it wants it to go.

Not sure what to do at this point in time. I can provide information as I continue to look through this. I would believe this is not expected behavior.

Activity

  1. jekkos commented on May 21, 2026

    @jekkos
    Member

    Is there any applicatoon code on the stack trace? I can try to reproduce tonight
    .are you using master docker?

  2. Hallsie commented on May 21, 2026

    @Hallsie
    Author

    Is there any applicatoon code on the stack trace? I can try to reproduce tonight .are you using master docker?

    One moment... There were two issues. Let me hunt them down...

    This was the initial one:
    SYSTEMPATH/Encryption/Encryption.php : 133 — CodeIgniter\Encryption\Exceptions\EncryptionException::forNeedsStarterKey ()

    126 }127128 if (! in_array($this->driver, $this->drivers, true)) {129 throw EncryptionException::forUnKnownHandler($this->driver);130 }131132 if (empty($this->key)) {133 throw EncryptionException::forNeedsStarterKey();134 }135136 $this->hmacKey = bin2hex(\hash_hkdf($this->digest, $this->key));137138 $handlerName = 'CodeIgniter\Encryption\Handlers' . $this->driver . 'Handler';139 $this->encrypter = new $handlerName($config);140SYSTEMPATH/Config/Services.php : 256 — CodeIgniter\Encryption\Encryption->initialize ( arguments )

    To fix that we generated a key and added the line to the docker-compose.yml file:

    encryption.key: "hex2bin:[key here]"

    But that did not work. Troubleshooting the error it looked like it was nearly every place except for /app/.env which is where it needed to be.

    So we created /docker_volumes/ospos/config/.env then copied the current .env out to that location and then manually put the key in there in the encryption section where it says:
    encryption.key = ''

    and then added the line in the docker-compose.yml file in the volume section: /docker_volumes/ospos/config/.env:/app/.env

    reloaded and it worked. ALMOST

    From there Sales would not work and it turned out it was because of when I tried to setup and test email before all of this there was some kind of key that was used to encrypt the settings perhaps? We were getting "Authentication failed" error on the decryption when the sales module was loading the mail module.

    The fix for that ended up being that now that we set the key and reloaded, I just went into the settings and saved the email password again. That overrode whatever it was looking for before with the new information that we have all the keys for.

    All was well after that.

    I have not tested email again to see WHAT was not working there. All I ever get is just a red message saying it cannot send it. I attempted to turn the logging level in the compose.yml file to 4 but that did nothing.

    I hope all this helps.

  3. 5 remaining items

  4. jekkos commented on Sep 7, 2026

    @jekkos
    Member

    Solution (no .env writes needed in Docker) — and why we shouldn't make .env writable to "fix" this:

    Inject the secrets as env vars instead of writing them to the container's .env. Both are already honored by the app:

    In compose it's just an environment: entry. Note the outer .env that docker compose reads is a different file from the app's $ROOTPATH/.env — it lives on the host and never enters the container:

    services:
      ospos:
        image: jekkos/opensourcepos:master
        environment:
          - ENCRYPTION_KEY=${ENCRYPTION_KEY:?set in the compose .env}
          - throttle.key=${THROTTLE_KEY:?set in the compose .env}

    openssl rand -hex 32 gives you both values.

    Why not make ROOTPATH/.env writable just so the runtime can persist an auto-generated key:

    • .env holds long-lived secrets (the encryption key and the throttle key). The image currently keeps the app effectively read-only — only uploads/ and writable/logs are mounted in. Making the root writable so code can create/modify a file that contains secrets expands the mutable surface (a second container sharing that volume, a mis-permissioned mount, or a write-path traversal) to include those secrets.
    • Keeping secrets in the process environment, not the mutable filesystem, is the standard "no secrets in the image/filesystem" posture — and it's already what CI does here.
    • writable/ is the documented "safe to write" area for data. Mixing secret configuration into it (or forcing root to be writable) is a different kind of risk than data the app owns.

    So the clean fix for #4554 is: ship the ENCRYPTION_KEY env var, document throttle.key on the image, and have docker compose set both. No .env writes, no shared key baked into the image, nothing to lose when the container is recreated — and no widening of the writable surface. This also unblocks #4656's concern about writing to .env in that environment.

  5. added this to the 3.4.2 milestone on Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions