Skip to content

Conversation

meirish
Copy link
Collaborator

@meirish meirish commented Apr 4, 2018

Some background:

  1. We use a CSP header with connect-src 'self'; to restrict any network calls made from the UI.
  2. If Vault's request forwarding mechanism does not work for any reason, it will fall back to redirecting any request to a standby node to the active node.

When 1 & 2 collide, and you attempt to authenticate via the UI on a standby node without request forwarding, the UI redirects to a domain other than self and the user sees an unhelpful error.

So! Now we detect CSP violations and show a (hopefully) more helpful error. We considered also displaying a link to the leader, but with the various ways Vault can be deployed, it may not be the case that the address of the active node that can be retrieved from the API would be resolvable in the browser and decided against that option.

screen shot 2018-04-04 at 3 30 32 pm
screen shot 2018-04-04 at 4 28 10 pm

@jefferai
Copy link
Member

jefferai commented Apr 4, 2018

Seems totally reasonable 🤔

@meirish meirish requested review from a team and joshuaogle April 4, 2018 21:47
Copy link

@alisdair alisdair left a comment

Choose a reason for hiding this comment

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

Neat solution and nice tests! 👍


remove() {
window.document.removeEventListener('securitypolicyviolation', this.handleCSP, true);
},
Copy link

Choose a reason for hiding this comment

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

Definitely not a change request, but I wondered how this service would look with ember-concurrency's waitForEvent. Untested:

import Ember from 'ember';
import { task, waitForEvent } from 'ember-concurrency';

const { Service, computed } = Ember;

export default Service.extend({
  events: [],
  connectionViolations: computed.filterBy('events', 'violatedDirective', 'connect-src'),

  attach() {
    this.get('monitor').perform();
  },

  remove() {
    this.get('monitor').cancelAll();
  },

  monitor: task(function*() {
    this.get('events').clear();

    while (let event = waitForEvent(window.document.body, 'securitypolicyviolation')) {
      this.get('events').addObject(event);
    }
  }).restartable(),
});

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oooo that is super nice, I may try updating that later. ❤ e-c.

Copy link
Member

@thrashr888 thrashr888 left a comment

Choose a reason for hiding this comment

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

Another nit: The icon, "Error", text seems a little tight to me, like the "Error" could use more space on the right or move the text to the next line.

@@ -25,9 +27,21 @@ export default Ember.Component.extend({
return `auth-form/${type}`;
}),

hasCSPError: computed.alias('csp.connectionViolations.firstObject'),

cspErrorText: `This is a standby Vault node but can't communicate with the active node via request forwarding. Sign in at the active node to use the Vault UI.`,
Copy link
Member

Choose a reason for hiding this comment

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

Nit: there's no templated code in here or in the string used in the tests below. Maybe you're just using it since the can't is in there?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah originally it was multi-line because it's a beefy error, but then I took that out so I didn't have to trim whitespace in tests 😂. THEN, when I went to single quote I noticed the can't and decided to leave the `s.

@meirish
Copy link
Collaborator Author

meirish commented Apr 5, 2018

@thrashr888 I'll follow up with @joshuaogle - my worry is it'll create a "hole" in the text block, but if we make the change I'll address it in a separate PR because we have a number of error / message components like that.

@meirish meirish merged commit e414458 into master Apr 5, 2018
@meirish meirish deleted the ui-request-forwarding-error branch April 5, 2018 21:36
@meirish meirish mentioned this pull request Apr 6, 2018
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.

4 participants