Skip to content
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

Add backend support for alternate base dir (subdir/subpath) hosting #868

Merged
merged 4 commits into from
Feb 22, 2020

Conversation

jjlin
Copy link
Contributor

@jjlin jjlin commented Feb 19, 2020

To use this, include a path in the DOMAIN URL, e.g.:

  • DOMAIN=https://example.com/custom-path
  • DOMAIN=https://example.com/multiple/levels/are/ok

Resolves #241, #488, #528, #767, and maybe others when combined with
dani-garcia/bw_web_builds#11 (web vault support).

@jjlin
Copy link
Contributor Author

jjlin commented Feb 19, 2020

BTW, this is my first time writing any code in Rust, so feel free to let me know if I'm doing anything weird. I'll also comment on a few specific changes a bit later.

@@ -6,10 +6,10 @@
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Bitwarden_rs Admin Panel</title>

<link rel="stylesheet" href="/bwrs_static/bootstrap.css" />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These paths all need to be relative to work with a different base dir.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed it to instead use an absolute path with the domain_path variable to avoid the / at the end issue that you mention for the emails

@@ -3,6 +3,6 @@ Invitation accepted
<html>
<p>
Your invitation for <b>{{email}}</b> to join <b>{{org_name}}</b> was accepted.
Please <a href="{{url}}">log in</a> to the bitwarden_rs server and confirm them from the organization management page.
Please <a href="{{url}}/">log in</a> to the bitwarden_rs server and confirm them from the organization management page.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a / after all bare {{url}} links because, for reasons I don't quite understand, if the base URL is https://example.com/my/path, then visiting the web vault at https://example.com/my/path results in rendering issues, while https://example.com/my/path/ (with trailing /) works fine.

@@ -240,6 +242,10 @@ make_config! {
domain: String, true, def, "http://localhost".to_string();
/// Domain Set |> Indicates if the domain is set by the admin. Otherwise the default will be used.
domain_set: bool, false, def, false;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like domain_set could be made auto as well, but maybe there's some subtlety I'm missing, so I left it as is.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pub static ref JWT_DELETE_ISSUER: String = format!("{}|delete", CONFIG.domain());
pub static ref JWT_VERIFYEMAIL_ISSUER: String = format!("{}|verifyemail", CONFIG.domain());
pub static ref JWT_ADMIN_ISSUER: String = format!("{}|admin", CONFIG.domain());
pub static ref JWT_LOGIN_ISSUER: String = format!("{}|login", CONFIG.domain_origin());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to domain_origin() instead of domain() to avoid JWT encode/decode issues in case the installation is moved to a different base dir. Note that in the usual case where the backend is hosted at the root of the domain, domain_origin() and domain() should be identical.

@jjlin
Copy link
Contributor Author

jjlin commented Feb 19, 2020

I've also added docs on the wiki: Using an alternate base dir

Copy link
Owner

@dani-garcia dani-garcia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I've pushed a change to use the fixed web vault so when this is merged we get a working image in one docker build.

I've also used absolute paths in the admin page to solve the / issues, the emails and web vault are fine as it is.

Thanks for your work, @jjlin!

@@ -240,6 +242,10 @@ make_config! {
domain: String, true, def, "http://localhost".to_string();
/// Domain Set |> Indicates if the domain is set by the admin. Otherwise the default will be used.
domain_set: bool, false, def, false;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -6,10 +6,10 @@
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Bitwarden_rs Admin Panel</title>

<link rel="stylesheet" href="/bwrs_static/bootstrap.css" />
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed it to instead use an absolute path with the domain_path variable to avoid the / at the end issue that you mention for the emails

@@ -1,6 +1,6 @@
<main class="container">
<div id="users-block" class="my-3 p-3 bg-white rounded shadow">
<h6 class="border-bottom pb-2 mb-0">Registered Users</h6>
<h6 class="border-bottom pb-2 mb-0">Registered Users {{urlpath}}</h6>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was it intentional for this {{urlpath}} to be here?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, no that was me checking that the urlpath was set to the correct value, forgot to remove it!

@dani-garcia dani-garcia merged commit 8a5450e into dani-garcia:master Feb 22, 2020
@jjlin jjlin deleted the alt-base branch February 23, 2020 04:10
thelittlefireman pushed a commit to thelittlefireman/bitwarden_rs that referenced this pull request Mar 19, 2021
Add backend support for alternate base dir (subdir/subpath) hosting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Run locally at suburl
2 participants