Skip to content

Commit aa4661b

Browse files
chore(auth): Deprecate API keys (#2934)
### Description API keys have been deprecated in favor of Auth Tokens over seven years ago on the backend. Here, we deprecate them in the CLI, in preparation to drop support from Sentry CLI 3.0.0. ### Issues - Resolves #2872 - Resolves [CLI-198](https://linear.app/getsentry/issue/CLI-198/deprecate-api-key-authentication)
1 parent e9436cd commit aa4661b

File tree

8 files changed

+36
-7
lines changed

8 files changed

+36
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Deprecations
6+
7+
- Deprecated API key authentication (#2934)[https://github.com/getsentry/sentry-cli/pull/2934]. Users who are still using API keys to authenticate Sentry CLI should generate and use an [Auth Token](https://docs.sentry.io/account/auth-tokens/) instead.
8+
59
### Improvements
610

711
- The `sentry-cli debug-files bundle-jvm` no longer makes any HTTP requests to Sentry, meaning auth tokens are no longer needed, and the command can be run offline ([#2926](https://github.com/getsentry/sentry-cli/pull/2926)).

src/api/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1411,6 +1411,7 @@ impl<'a> AuthenticatedApi<'a> {
14111411
region_url.ok().map(|url| url.into())
14121412
}
14131413
},
1414+
#[expect(deprecated, reason = "Auth key is deprecated.")]
14141415
Auth::Key(_) => {
14151416
log::warn!(
14161417
"Auth key is not supported for region-specific API. Falling back to default region."
@@ -1771,9 +1772,10 @@ impl ApiRequest {
17711772
pub fn with_auth(mut self, auth: &Auth) -> ApiResult<Self> {
17721773
self.is_authenticated = true;
17731774
match *auth {
1775+
#[expect(deprecated, reason = "API key is deprecated.")]
17741776
Auth::Key(ref key) => {
17751777
self.handle.username(key)?;
1776-
debug!("using key based authentication");
1778+
debug!("using deprecated key based authentication");
17771779
Ok(self)
17781780
}
17791781
Auth::Token(ref token) => {

src/commands/info.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ fn describe_auth(auth: Option<&Auth>) -> &str {
5959
match auth {
6060
None => "Unauthorized",
6161
Some(&Auth::Token(_)) => "Auth Token",
62-
Some(&Auth::Key(_)) => "API Key",
62+
#[expect(deprecated, reason = "API key is deprecated.")]
63+
Some(&Auth::Key(_)) => "API Key (deprecated)",
6364
}
6465
}
6566

@@ -74,6 +75,7 @@ fn get_config_status_json() -> Result<()> {
7475

7576
rv.auth.auth_type = config.get_auth().map(|val| match val {
7677
Auth::Token(_) => "token".into(),
78+
#[expect(deprecated, reason = "API key is deprecated.")]
7779
Auth::Key(_) => "api_key".into(),
7880
});
7981
rv.auth.successful =

src/commands/login.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
140140
fn get_org_from_auth(auth: &Auth) -> Option<&str> {
141141
match auth {
142142
Auth::Token(token) => get_org_from_token(token),
143+
#[expect(deprecated, reason = "API key is deprecated.")]
143144
Auth::Key(_) => None,
144145
}
145146
}

src/commands/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,15 @@ fn preexecute_hooks() -> Result<bool> {
138138

139139
fn configure_args(config: &mut Config, matches: &ArgMatches) {
140140
if let Some(api_key) = matches.get_one::<String>("api_key") {
141-
config.set_auth(Auth::Key(api_key.to_owned()));
141+
log::warn!(
142+
"[DEPRECTATION NOTICE] API key authentication and the --api-key argument are \
143+
deprecated. \
144+
Please generate an auth token, and use the --auth-token argument instead."
145+
);
146+
147+
#[expect(deprecated, reason = "Auth key is deprecated.")]
148+
let auth = Auth::Key(api_key.to_owned());
149+
config.set_auth(auth);
142150
}
143151

144152
if let Some(auth_token) = matches.get_one::<AuthToken>("auth_token") {
@@ -188,7 +196,8 @@ fn app() -> Command {
188196
Arg::new("api_key")
189197
.value_name("API_KEY")
190198
.long("api-key")
191-
.help("Use the given Sentry API key."),
199+
.hide(true)
200+
.help("[DEPRECATED] Use the given Sentry API key."),
192201
)
193202
.arg(
194203
Arg::new("log_level")

src/config.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const MAX_RETRIES_INI_KEY: &str = "max_retries";
3636
/// Represents the auth information
3737
#[derive(Debug, Clone)]
3838
pub enum Auth {
39+
#[deprecated(note = "Auth Key authentication is deprecated.")]
3940
Key(String),
4041
Token(AuthToken),
4142
}
@@ -196,6 +197,7 @@ impl Config {
196197
val.raw().expose_secret().clone(),
197198
);
198199
}
200+
#[expect(deprecated, reason = "API key is deprecated.")]
199201
Some(Auth::Key(ref val)) => {
200202
self.ini.set_to(Some("auth"), "api_key".into(), val.clone());
201203
}
@@ -734,15 +736,26 @@ impl Clone for Config {
734736
}
735737
}
736738

737-
#[expect(clippy::manual_map)]
738739
fn get_default_auth(ini: &Ini) -> Option<Auth> {
739740
if let Ok(val) = env::var("SENTRY_AUTH_TOKEN") {
740741
Some(Auth::Token(val.into()))
741742
} else if let Ok(val) = env::var("SENTRY_API_KEY") {
743+
log::warn!(
744+
"[DEPRECTATION NOTICE] API key authentication and the `SENTRY_API_KEY` environment \
745+
variable are deprecated. \
746+
Please generate and set an auth token using `SENTRY_AUTH_TOKEN` instead."
747+
);
748+
#[expect(deprecated, reason = "API key is deprecated.")]
742749
Some(Auth::Key(val))
743750
} else if let Some(val) = ini.get_from(Some("auth"), "token") {
744751
Some(Auth::Token(val.into()))
745752
} else if let Some(val) = ini.get_from(Some("auth"), "api_key") {
753+
log::warn!(
754+
"[DEPRECTATION NOTICE] API key authentication and the `api_key` field in the \
755+
Sentry CLI config file are deprecated. \
756+
Please generate and set an auth token instead."
757+
);
758+
#[expect(deprecated, reason = "API key is deprecated.")]
746759
Some(Auth::Key(val.to_owned()))
747760
} else {
748761
None

tests/integration/_cases/help/help-windows.trycmd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ Options:
3838
--header <KEY:VALUE> Custom headers that should be attached to all requests
3939
in key:value format.
4040
--auth-token <AUTH_TOKEN> Use the given Sentry auth token.
41-
--api-key <API_KEY> Use the given Sentry API key.
4241
--log-level <LOG_LEVEL> Set the log output verbosity. [possible values: trace, debug, info,
4342
warn, error]
4443
--quiet Do not print any output while preserving correct exit code. This

tests/integration/_cases/help/help.trycmd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ Options:
3939
--header <KEY:VALUE> Custom headers that should be attached to all requests
4040
in key:value format.
4141
--auth-token <AUTH_TOKEN> Use the given Sentry auth token.
42-
--api-key <API_KEY> Use the given Sentry API key.
4342
--log-level <LOG_LEVEL> Set the log output verbosity. [possible values: trace, debug, info,
4443
warn, error]
4544
--quiet Do not print any output while preserving correct exit code. This

0 commit comments

Comments
 (0)