-
-
Notifications
You must be signed in to change notification settings - Fork 138
Support rootless (backwards compatible) #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
b3c8d67
db779f4
ac55256
5368a23
b62e016
e117b46
2fc6d54
a7c8aee
51a8142
045c7bb
166a822
b874fa9
18040d4
037bc21
97ae2ee
7f15c4b
3e0cc0f
a7fcf0f
6e7290e
ef7ba0b
a68521b
cb2cf75
4e5d190
651cbbd
7ef9657
d483aa1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,34 +2,67 @@ | |||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| set -ex | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # Initialize | ||||||||||||||||||||||||||||||||||
| if [[ $1 == init ]]; then | ||||||||||||||||||||||||||||||||||
| echo "The init command is deprecated. Go to our github repo for setup instructions." | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if [[ $HOME == "/" ]] then | ||||||||||||||||||||||||||||||||||
| echo "When running rootless, you must set a home dir as the HOME env var. We recommend /data. Make sure it is writable by the user running the container (currently id is $(id -u) and HOME is $HOME)." | ||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # give friendly error if you don't have protonmail data | ||||||||||||||||||||||||||||||||||
| if [[ `find $HOME | wc -l` == 1 ]]; then # 1 because find $HOME will always return $HOME | ||||||||||||||||||||||||||||||||||
| echo 'Protonmail does not seem to have been initialized yet. Enter the container with something like `docker exec -it <container_name>` and type "help" for instructions on how to set up the ProtonMail Bridge' | ||||||||||||||||||||||||||||||||||
| timeout 10s /protonmail/proton-bridge --noninteractive # this starts the bridge in non-interactive mode and kills it after 20 seconds, so we can populate the vault with default values and override them with the env variables in the later step. | ||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this exists with an error for me when running as non-root on a new volume: As you have Replacing this with |
||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # give friendly error if the user doesn't own the data | ||||||||||||||||||||||||||||||||||
| if [[ $(id -u) != 0 ]]; then | ||||||||||||||||||||||||||||||||||
| if [[ `find $HOME/.* -not -user $(id -u) | wc -l` != 0 ]]; then | ||||||||||||||||||||||||||||||||||
| echo "You do not own the data in $HOME. Please chown it to $(id -u), run the container as the owner of the data or run the container as root." | ||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # Initialize pass | ||||||||||||||||||||||||||||||||||
| if [[ ! -f $HOME/.gnupg ]]; then | ||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be |
||||||||||||||||||||||||||||||||||
| echo "No GPG key found in $HOME/.gnupg. Running gpg --generate-key." | ||||||||||||||||||||||||||||||||||
| gpg --generate-key --batch /protonmail/gpgparams | ||||||||||||||||||||||||||||||||||
| pass init pass-key | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # Kill the other instance as only one can be running at a time. | ||||||||||||||||||||||||||||||||||
| # This allows users to run entrypoint init inside a running conainter | ||||||||||||||||||||||||||||||||||
| # which is useful in a k8s environment. | ||||||||||||||||||||||||||||||||||
| # || true to make sure this would not fail in case there is no running instance. | ||||||||||||||||||||||||||||||||||
| pkill protonmail-bridge || true | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # Login | ||||||||||||||||||||||||||||||||||
| /protonmail/proton-bridge --cli $@ | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
| # delete lock files if they exist - this can happen if the container is restarted forcefully | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||
| if [[ `find $HOME -name "*.lock" | wc -l` != 0 ]]; then | ||||||||||||||||||||||||||||||||||
| echo "Deleting lock files in $HOME. This can happen if the container is restarted forcefully." | ||||||||||||||||||||||||||||||||||
| find $HOME -name "*.lock" -delete | ||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there might be a chance of two containers mounting the same filesystems, and the other one still running?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. Can you help with a contribution for this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm quite interested in a rootless setup for that container, so @simonfelding if you could review the changes it would make it easier for users to just checkout that PR instead of having to do the diffs :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe the "Y" should be case insensitive during that prompt, would be a bit better There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually I can't use |
||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # socat will make the conn appear to come from 127.0.0.1 | ||||||||||||||||||||||||||||||||||
| # ProtonMail Bridge currently expects that. | ||||||||||||||||||||||||||||||||||
| # It also allows us to bind to the real ports :) | ||||||||||||||||||||||||||||||||||
| # socat will make the conn appear to come from 127.0.0.1 | ||||||||||||||||||||||||||||||||||
| # ProtonMail Bridge currently expects that. | ||||||||||||||||||||||||||||||||||
| # It also allows us to bind to the real ports :) | ||||||||||||||||||||||||||||||||||
| if [[ $(id -u) == 0 ]]; then | ||||||||||||||||||||||||||||||||||
| socat TCP-LISTEN:25,fork TCP:127.0.0.1:1025 & | ||||||||||||||||||||||||||||||||||
| socat TCP-LISTEN:143,fork TCP:127.0.0.1:1143 & | ||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||
| socat TCP-LISTEN:2025,fork TCP:127.0.0.1:1025 & | ||||||||||||||||||||||||||||||||||
| socat TCP-LISTEN:2143,fork TCP:127.0.0.1:1143 & | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # Start protonmail | ||||||||||||||||||||||||||||||||||
| # Fake a terminal, so it does not quit because of EOF... | ||||||||||||||||||||||||||||||||||
| rm -f faketty | ||||||||||||||||||||||||||||||||||
| mkfifo faketty | ||||||||||||||||||||||||||||||||||
| cat faketty | /protonmail/proton-bridge --cli $@ | ||||||||||||||||||||||||||||||||||
| # Broken until https://github.com/ProtonMail/proton-bridge/issues/512 is resolved. | ||||||||||||||||||||||||||||||||||
| # check if the vault-editor can read the config | ||||||||||||||||||||||||||||||||||
| /protonmail/vault-editor read 2>&1 1>/dev/null | ||||||||||||||||||||||||||||||||||
| # Modify the protonmail config with env variables and expected values. Env variables must be converted from string to boolean. | ||||||||||||||||||||||||||||||||||
| /protonmail/vault-editor read | \ | ||||||||||||||||||||||||||||||||||
| jq '.Settings.AutoUpdate = (env.PROTONMAIL_AutoUpdate | if . == "true" then true else false end) | ||||||||||||||||||||||||||||||||||
| | .Settings.TelemetryDisabled = (env.PROTONMAIL_TelemetryDisabled | if . == "true" then true else false end) | ||||||||||||||||||||||||||||||||||
| | .Settings.GluonDir |= "\(env.HOME)/.local/share/protonmail/bridge-v3/gluon" | ||||||||||||||||||||||||||||||||||
| | .Settings.Autostart = false | ||||||||||||||||||||||||||||||||||
| | .Settings.SMTPPort = 1025 | ||||||||||||||||||||||||||||||||||
| | .Settings.IMAPPort = 1143 ' \ | ||||||||||||||||||||||||||||||||||
| | /protonmail/vault-editor write | ||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is that future proof? I believe using |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
| # Start protonmail | ||||||||||||||||||||||||||||||||||
| echo "Starting ProtonMail Bridge. Connect to the CLI with `docker exec -it <container_name>` and type 'help' for instructions." | ||||||||||||||||||||||||||||||||||
| /protonmail/proton-bridge --cli $@ | ||||||||||||||||||||||||||||||||||
| echo "ProtonMail bridge stopped. waiting 30 seconds before exiting in order to preserve the logs." | ||||||||||||||||||||||||||||||||||
| sleep 30 # so we have time to read the logs in case of a crash loop | ||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't it be better to delete any remaining lock files at the end of that script too? For some reason the bridge seems to not clean those sometimes for me. But in any case at the last line of the entrypoint any remaining lock file has to have been forgotten and can be deleted safely no? |
||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried again, from scratch this time, and an issue is that the volume gets mounted with the permission of the directory you mount it on in the container. To fix this, it looks like creating That does mean 'forcing' to mount on |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,9 +12,13 @@ RUN bash /install.sh | |
| FROM debian:sid-slim | ||
| LABEL maintainer="Simon Felding <sife@adm.ku.dk>" | ||
|
|
||
| # These are only exported if running as root | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure "exported" is the correct word. Maybe you meant "used"? |
||
| EXPOSE 25/tcp | ||
| EXPOSE 143/tcp | ||
|
|
||
| EXPOSE 2025/tcp | ||
| EXPOSE 2143/tcp | ||
|
|
||
| WORKDIR /protonmail | ||
|
|
||
| # Copy bash scripts | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,20 +30,44 @@ if [[ $1 == init ]]; then | |
| pass init pass-key | ||
|
|
||
| # Login | ||
| protonmail-bridge --cli | ||
| protonmail-bridge --cli $@ | ||
|
|
||
| else | ||
| if [[ $HOME == "/" ]] then | ||
| echo "When running rootless, you must set a home dir as the HOME env var. We recommend /data. Make sure it is writable by the user running the container (currently id is $(id -u) and HOME is $HOME)." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # give friendly error if you don't have protonmail data | ||
| if [[ `find $HOME | wc -l` == 1 ]]; then # 1 because find $HOME will always return $HOME | ||
| echo "No files found - start the container with the init command, or copy/mount files into it at $HOME first. Sleeping 5 minutes before exiting so you have time to copy the files over." | ||
| sleep 300 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # give friendly error if the user doesn't own the data | ||
| if [[ $(id -u) != 0 ]]; then | ||
| if [[ `find $HOME/.* -not -user $(id -u) | wc -l` != 0 ]]; then | ||
| echo "You do not own the data in $HOME. Please chown it to $(id -u), run the container as the owner of the data or run the container as root." | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about: "You do not own some or all of the data in $HOME" and "recursively chown it"
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, that's better. |
||
| exit 1 | ||
| fi | ||
| fi | ||
|
|
||
| # delete lock files if they exist - this can happen if the container is restarted forcefully | ||
| find $HOME -name "*.lock" -delete | ||
|
|
||
| # socat will make the conn appear to come from 127.0.0.1 | ||
| # ProtonMail Bridge currently expects that. | ||
| # It also allows us to bind to the real ports :) | ||
| socat TCP-LISTEN:25,fork TCP:127.0.0.1:1025 & | ||
| socat TCP-LISTEN:143,fork TCP:127.0.0.1:1143 & | ||
| if [[ $(id -u) == 0 ]]; then | ||
| socat TCP-LISTEN:25,fork TCP:127.0.0.1:1025 & | ||
| socat TCP-LISTEN:143,fork TCP:127.0.0.1:1143 & | ||
| fi | ||
|
|
||
| socat TCP-LISTEN:2025,fork TCP:127.0.0.1:1025 & | ||
| socat TCP-LISTEN:2143,fork TCP:127.0.0.1:1143 & | ||
|
|
||
| # Start protonmail | ||
| # Fake a terminal, so it does not quit because of EOF... | ||
| rm -f faketty | ||
| mkfifo faketty | ||
| cat faketty | protonmail-bridge --cli | ||
| /protonmail/proton-bridge --noninteractive $@ | ||
|
|
||
| fi | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,19 @@ | ||
| version: '2.1' | ||
|
|
||
| services: | ||
| protonmail-bridge: | ||
| image: shenxn/protonmail-bridge | ||
| container_name: protonmail-bridge | ||
| ports: | ||
| - 1025:25/tcp | ||
| - 1143:143/tcp | ||
| restart: unless-stopped | ||
| volumes: | ||
| - protonmail:/root | ||
| stdin_open: true | ||
| tty: true | ||
| logging: | ||
| options: | ||
| max-size: "1m" | ||
| max-file: "10" | ||
| volumes: | ||
| protonmail: | ||
| name: protonmail |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not clear. I suggest this:
Edit: oh you meant to type
helpin the console right? For some reason the--cli helpjust showed the man page in the docker logs so maybe the bridge's cli changed with updates or something?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to use
expectto automatically add theaddinside the console? We could even usedocker secretsto store the protonmail account info just during the init.