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

feat: strict behavior #474

Merged
merged 10 commits into from
Jul 4, 2024
Merged

feat: strict behavior #474

merged 10 commits into from
Jul 4, 2024

Conversation

nunogois
Copy link
Member

@nunogois nunogois commented Jul 3, 2024

https://linear.app/unleash/issue/2-2370/add-closed-mode

Adds the concept of "strict" and "dynamic" behaviors when running in Edge mode.

  • Strict: The new recommended behavior. New tokens are not accepted unless they are subsumed by registered tokens.
  • Dynamic: The default behavior. New tokens are automatically registered and features will be fetched for them.

This means no change in behavior for existing users. However we recommend edge mode is started with --strict from now on. The plan is to drop this sometime in the future and instead always default to strict mode.

Some tests assumed the "dynamic" behavior by default, so they were adapted accordingly.

Copy link

github-actions bot commented Jul 3, 2024

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Manifest Files

Copy link
Member

@sighphyre sighphyre left a comment

Choose a reason for hiding this comment

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

Ye, it's sexy. Nothing here that I feel the need to block this for but I do feel strongly about adding the new error type over modifying the existing one. It's a personal feeling so I won't cry if no one agrees with me

server/src/http/feature_refresher.rs Outdated Show resolved Hide resolved
server/src/http/feature_refresher.rs Outdated Show resolved Hide resolved
server/src/http/feature_refresher.rs Outdated Show resolved Hide resolved
server/src/error.rs Outdated Show resolved Hide resolved
server/src/http/feature_refresher.rs Outdated Show resolved Hide resolved
Copy link
Member

@sighphyre sighphyre left a comment

Choose a reason for hiding this comment

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

Meant to approve

🍌

@chriswk
Copy link
Member

chriswk commented Jul 3, 2024

We should make sure that we fail hard and exit if you start edge in closed mode with no tokens.

@@ -174,6 +174,10 @@ pub struct EdgeArgs {
/// Token header to use for both edge authorization and communication with the upstream server.
#[clap(long, env, global = true, default_value = "Authorization")]
pub token_header: TokenHeader,

/// If set to true, Edge starts in open mode. Open mode means that Edge will accept tokens outside of the scope of the startup tokens
#[clap(short, long, env, default_value_t = true)]
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we default to false here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, addressed in e31c1ce

@nunogois
Copy link
Member Author

nunogois commented Jul 3, 2024

We should make sure that we fail hard and exit if you start edge in closed mode with no tokens.

Agreed, that's something that came to mind after our session. What do you think of this approach? 8459d1a

Also touches offline mode for consistency (and scouting, seems like offline mode was happy starting with no tokens?), but I'm happy to leave that out of this PR if you prefer.

Copy link
Contributor

@gardleopard gardleopard left a comment

Choose a reason for hiding this comment

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

Closed vs Open mode. I think this is the major thing in this project for UX. I think that we should be careful on what we name the modes. Its not clear to me what closed and open means here. I think consistent mode vs eventual cosistent or deterministic vs non deterministic might be some options to consider for this. Id like us to involve @FredrikOseberg before selecting the name of this mode.

@FredrikOseberg
Copy link

Looks like I'm a bit late to the party and without that much context. But it looks to me like we already have Edge mode and Offline mode as top level modes. These modes seem to be changing the default behavior of Edge mode if I'm reading this right? So we have two sub-modes of Edge mode? Is that the correct interpretation here?

@nunogois
Copy link
Member Author

nunogois commented Jul 3, 2024

Looks like I'm a bit late to the party and without that much context. But it looks to me like we already have Edge mode and Offline mode as top level modes. These modes seem to be changing the default behavior of Edge mode if I'm reading this right? So we have two sub-modes of Edge mode? Is that the correct interpretation here?

I think that's spot on.

Edge and Offline modes as top level modes, just like before.

Edge behaved like the new "open" mode. We now want it to behave like the new "closed" mode by default, but leave "open" mode as an option.

The difference between the modes is explained in the PR description. Essentially "open" mode allows you to hit Edge with any token. Once validated, that token is added to the list of tokens to refresh (fetch features for). "Closed" mode will return 403 for tokens that, once validated, are not subsumed by the currently known tokens.

The idea is that e.g. you start Edge with a wildcard token for an environment, and any token that matches that environment should be OK, even if it's narrower in scope (e.g. same environment, but specific project). However tokens for other environments are denied, instead of dynamically added to the list.

@FredrikOseberg
Copy link

Looks like I'm a bit late to the party and without that much context. But it looks to me like we already have Edge mode and Offline mode as top level modes. These modes seem to be changing the default behavior of Edge mode if I'm reading this right? So we have two sub-modes of Edge mode? Is that the correct interpretation here?

I think that's spot on.

Edge and Offline modes as top level modes, just like before.

Edge behaved like the new "open" mode. We now want it to behave like the new "closed" mode by default, but leave "open" mode as an option.

The difference between the modes is explained in the PR description. Essentially "open" mode allows you to hit Edge with any token. Once validated, that token is added to the list of tokens to refresh (fetch features for). "Closed" mode will return 403 for tokens that, once validated, are not subsumed by the currently known tokens.

The idea is that e.g. you start Edge with a wildcard token for an environment, and any token that matches that environment should be OK, even if it's narrower in scope (e.g. same environment, but specific project). However tokens for other environments are denied, instead of dynamically added to the list.

Is it confusing to refer to it as a mode then? I would expect mode to be a state that I can start Edge in based on the current implementation of mode. For example:

Edge mode | Offline mode | Open mode | Closed mode

While in reality it seems like these are behaviors of edge mode. Would it make more sense to refer to it as Edge mote behavior: strict or dynamic behavior? I feel like we might be mixing concepts we already have here.

@sighphyre
Copy link
Member

Okay I thought about this a lot more and I spoke to @gardleopard. What's our plan for open/closed (or whatever we want to call it). I'd really like to make the open mode go away medium term. I think it's a trap and my personal feelings around the flag here is to give people a window to migrate away from open mode

That aside, I think @FredrikOseberg's suggestion of dynamic/strict is a goodie.

@sighphyre
Copy link
Member

Edge mode | Offline mode | Open mode | Closed mode

While in reality it seems like these are behaviors of edge mode. Would it make more sense to refer to it as Edge mote behavior: strict or dynamic behavior? I feel like we might be mixing concepts we already have here.

Okay. Also this. What makes sense to me is Edge | Offline | Closed (the names need some love maybe). But really Open/Closed can't affect offline mode

@nunogois nunogois changed the title feat: closed mode feat: strict behavior Jul 3, 2024
@nunogois
Copy link
Member Author

nunogois commented Jul 3, 2024

Following the recent comments and discussions I made some changes.
I recommend reading the updated PR description: #474 (comment)

I think dynamic/strict behaviors are nice terms for this. Definitely better than open/closed modes.
You're both correct: These are not new top-level modes. These are new behaviors that only apply to Edge mode.

I agree that we should introduce this gracefully. The default is now the "dynamic" behavior, so this means no breaking changes to existing users. However we're introducing the "strict" behavior, which is our new recommended way of starting Edge. We can have our quickstart command include --strict when we tackle the docs in a separate PR.

The idea is that sometime later we drop this in favor of always defaulting to the "strict" behavior instead.

WDYT?

Copy link

@FredrikOseberg FredrikOseberg left a comment

Choose a reason for hiding this comment

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

This looks good to me. I found a small remnant of the old naming.

@@ -204,6 +207,7 @@ impl Display for EdgeError {
EdgeError::NotReady => {
write!(f, "Edge is not ready to serve requests")
}
EdgeError::InvalidTokenOnClosedMode => write!(f, "Edge is running in closed mode and the token is not subsumed by any registered tokens"),

Choose a reason for hiding this comment

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

This needs to be updated to strict behavior I assume?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, nice catch! 1363734

@gardleopard
Copy link
Contributor

Are we not gonna put strict as the default behaviour and deprecate but support the dynamic behaviour?

@nunogois nunogois merged commit 9f01201 into main Jul 4, 2024
10 checks passed
@nunogois nunogois deleted the feat-closed-mode branch July 4, 2024 08:13
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.

5 participants