401 lines
15 KiB
Diff
401 lines
15 KiB
Diff
From 34fce86c0116ef2c888dfe7e474073b158bca8b3 Mon Sep 17 00:00:00 2001
|
|
From: Michal Srb <michal@redhat.com>
|
|
Date: Mon, 21 Feb 2022 00:49:51 +0100
|
|
Subject: [PATCH] [reporter-bugzilla] Use API key for authentication
|
|
|
|
Following change will take effect on February 28 2022:
|
|
|
|
"""
|
|
Applications making API calls to Bugzilla may no longer
|
|
authenticate using passwords or supplying API keys
|
|
in call parameters. Instead, API keys must be supplied
|
|
in the Authorization header.
|
|
"""
|
|
|
|
See the announcement for more details:
|
|
https://listman.redhat.com/archives/bugzilla-announce-list/2022-February/msg00000.html
|
|
|
|
Signed-off-by: Michal Srb <michal@redhat.com>
|
|
---
|
|
doc/report_Bugzilla.conf.txt | 7 +--
|
|
doc/reporter-bugzilla.txt | 14 ++---
|
|
src/gtk-helpers/secrets.c | 2 +-
|
|
src/plugins/bugzilla.conf | 7 +--
|
|
src/plugins/report_Bugzilla.conf | 3 +-
|
|
src/plugins/report_Bugzilla.xml.in.in | 13 ++--
|
|
src/plugins/reporter-bugzilla.c | 87 ++++++++-------------------
|
|
src/plugins/rhbz.c | 15 +++++
|
|
src/plugins/rhbz.h | 2 +
|
|
tests/bugzilla_plugin.at.in | 10 +--
|
|
10 files changed, 61 insertions(+), 99 deletions(-)
|
|
|
|
diff --git a/doc/report_Bugzilla.conf.txt b/doc/report_Bugzilla.conf.txt
|
|
index ea500ae6..ce7df911 100644
|
|
--- a/doc/report_Bugzilla.conf.txt
|
|
+++ b/doc/report_Bugzilla.conf.txt
|
|
@@ -12,11 +12,8 @@ This configuration file contains values for options defined in
|
|
|
|
Configuration file lines should have 'PARAM = VALUE' format. The parameters are:
|
|
|
|
-'Bugzilla_Login'::
|
|
- Login to Bugzilla account.
|
|
-
|
|
-'Bugzilla_Password'::
|
|
- Password to Bugzilla account.
|
|
+'Bugzilla_APIKey'::
|
|
+ API key for authentication to Bugzilla account.
|
|
|
|
'Bugzilla_BugzillaURL'::
|
|
Bugzilla HTTP(S) address. (default: https://bugzilla.redhat.com)
|
|
diff --git a/doc/reporter-bugzilla.txt b/doc/reporter-bugzilla.txt
|
|
index 2aee41e1..601d2a8f 100644
|
|
--- a/doc/reporter-bugzilla.txt
|
|
+++ b/doc/reporter-bugzilla.txt
|
|
@@ -57,11 +57,8 @@ and to user's local ~/.config/libreport/bugzilla.conf.
|
|
Configuration file lines should have 'PARAM = VALUE' format. The parameters are:
|
|
User's local configuration overrides the system wide configuration.
|
|
|
|
-'Login'::
|
|
- Login to Bugzilla account.
|
|
-
|
|
-'Password'::
|
|
- Password to Bugzilla account.
|
|
+'APIKey'::
|
|
+ API key for authentication to Bugzilla account.
|
|
|
|
'BugzillaURL'::
|
|
Bugzilla HTTP(S) address. (default: https://bugzilla.redhat.com)
|
|
@@ -175,11 +172,8 @@ ENVIRONMENT VARIABLES
|
|
Environment variables take precedence over values provided in
|
|
the configuration file.
|
|
|
|
-'Bugzilla_Login'::
|
|
- Login to Bugzilla account.
|
|
-
|
|
-'Bugzilla_Password'::
|
|
- Password to Bugzilla account.
|
|
+'Bugzilla_APIKey'::
|
|
+ API key for authentication to Bugzilla account.
|
|
|
|
'Bugzilla_BugzillaURL'::
|
|
Bugzilla HTTP(S) address. (default: https://bugzilla.redhat.com)
|
|
diff --git a/src/gtk-helpers/secrets.c b/src/gtk-helpers/secrets.c
|
|
index 65decaad..55c6ee51 100644
|
|
--- a/src/gtk-helpers/secrets.c
|
|
+++ b/src/gtk-helpers/secrets.c
|
|
@@ -66,7 +66,7 @@
|
|
|
|
For example, "report_Bugzilla" item will have the lookup attribute
|
|
like ("libreportEventConfig", "report_Bugzilla") and the secret value
|
|
- like ("Bugzilla_URL=https://bugzilla.redhat.com\0Bugzilla_Login=foo\0")
|
|
+ like ("Bugzilla_URL=https://bugzilla.redhat.com\0Bugzilla_APIKey=foo\0")
|
|
|
|
|
|
|
|
diff --git a/src/plugins/bugzilla.conf b/src/plugins/bugzilla.conf
|
|
index a7727392..a81348f8 100644
|
|
--- a/src/plugins/bugzilla.conf
|
|
+++ b/src/plugins/bugzilla.conf
|
|
@@ -7,10 +7,9 @@
|
|
# yes means that ssl certificates will be checked
|
|
SSLVerify = yes
|
|
|
|
-# your login has to exist, if you don't have any, please create one
|
|
-Login =
|
|
-# your password
|
|
-Password =
|
|
+# Bugzilla API key.
|
|
+# You can set up an API key by using the "API Key" tab in the Preferences pages.
|
|
+APIKey =
|
|
|
|
# SELinux guys almost always move filed bugs from component
|
|
# selinux-policy to another component.
|
|
diff --git a/src/plugins/report_Bugzilla.conf b/src/plugins/report_Bugzilla.conf
|
|
index f1a77f50..c9bfdd11 100644
|
|
--- a/src/plugins/report_Bugzilla.conf
|
|
+++ b/src/plugins/report_Bugzilla.conf
|
|
@@ -1,4 +1,3 @@
|
|
Bugzilla_BugzillaURL = https://bugzilla.redhat.com
|
|
-Bugzilla_Login =
|
|
-Bugzilla_Password =
|
|
+Bugzilla_APIKey =
|
|
Bugzilla_SSLVerify = yes
|
|
diff --git a/src/plugins/report_Bugzilla.xml.in.in b/src/plugins/report_Bugzilla.xml.in.in
|
|
index d6078a18..966d97f6 100644
|
|
--- a/src/plugins/report_Bugzilla.xml.in.in
|
|
+++ b/src/plugins/report_Bugzilla.xml.in.in
|
|
@@ -13,16 +13,11 @@
|
|
<support-restricted-access optionname="Bugzilla_CreatePrivate">yes</support-restricted-access>
|
|
|
|
<options>
|
|
- <option type="text" name="Bugzilla_Login">
|
|
- <_label>User name</_label>
|
|
+ <option type="text" name="Bugzilla_APIKey">
|
|
+ <_label>API key</_label>
|
|
<allow-empty>no</allow-empty>
|
|
- <_description>Bugzilla account user name</_description>
|
|
- <_note-html>You can create bugzilla.redhat.com account <a href="https://bugzilla.redhat.com/createaccount.cgi">here</a></_note-html>
|
|
- </option>
|
|
- <option type="password" name="Bugzilla_Password">
|
|
- <_label>Password</_label>
|
|
- <allow-empty>no</allow-empty>
|
|
- <_description>Bugzilla account password</_description>
|
|
+ <_description>Bugzilla API key</_description>
|
|
+ <_note-html>You can generate the API key for your Bugzilla account <a href="https://bugzilla.redhat.com/userprefs.cgi?tab=apikey">here</a></_note-html>
|
|
</option>
|
|
<option type="bool" name="Bugzilla_CreatePrivate">
|
|
<_label>Restrict access</_label>
|
|
diff --git a/src/plugins/reporter-bugzilla.c b/src/plugins/reporter-bugzilla.c
|
|
index b588454b..27aa63d2 100644
|
|
--- a/src/plugins/reporter-bugzilla.c
|
|
+++ b/src/plugins/reporter-bugzilla.c
|
|
@@ -75,7 +75,7 @@ int attach_file_item(struct abrt_xmlrpc *ax, const char *bug_id,
|
|
|
|
struct bugzilla_struct {
|
|
char *b_login;
|
|
- char *b_password;
|
|
+ char *b_api_key;
|
|
const char *b_bugzilla_url;
|
|
const char *b_bugzilla_xmlrpc;
|
|
char *b_product;
|
|
@@ -108,15 +108,10 @@ static void set_settings(struct bugzilla_struct *b, GHashTable *settings)
|
|
{
|
|
const char *environ;
|
|
|
|
- environ = getenv("Bugzilla_Login");
|
|
+ environ = getenv("Bugzilla_APIKey");
|
|
if (!environ)
|
|
- environ = g_hash_table_lookup(settings, "Login");
|
|
- b->b_login = g_strdup(environ ? environ : "");
|
|
-
|
|
- environ = getenv("Bugzilla_Password");
|
|
- if (!environ)
|
|
- environ = g_hash_table_lookup(settings, "Password");
|
|
- b->b_password = g_strdup(environ ? environ : "");
|
|
+ environ = g_hash_table_lookup(settings, "APIKey");
|
|
+ b->b_api_key = g_strdup(environ ? environ : "");
|
|
|
|
environ = getenv("Bugzilla_BugzillaURL");
|
|
if (!environ)
|
|
@@ -210,33 +205,16 @@ char *ask_bz_login(const char *message)
|
|
}
|
|
|
|
static
|
|
-char *ask_bz_password(const char *message)
|
|
+char *ask_bz_api_key(const char *message)
|
|
{
|
|
- char *password = libreport_ask_password(message);
|
|
- if (password == NULL || password[0] == '\0')
|
|
+ char *api_key = libreport_ask_password(message);
|
|
+ if (api_key == NULL || api_key[0] == '\0')
|
|
{
|
|
libreport_set_xfunc_error_retval(EXIT_CANCEL_BY_USER);
|
|
- error_msg_and_die(_("Can't continue without password"));
|
|
+ error_msg_and_die(_("Can't continue without API key"));
|
|
}
|
|
|
|
- return password;
|
|
-}
|
|
-
|
|
-static
|
|
-void login(struct abrt_xmlrpc *client, struct bugzilla_struct *rhbz)
|
|
-{
|
|
- log_warning(_("Logging into Bugzilla at %s"), rhbz->b_bugzilla_url);
|
|
-
|
|
- while (!rhbz_login(client, rhbz->b_login, rhbz->b_password))
|
|
- {
|
|
- free(rhbz->b_login);
|
|
- g_autofree char *question = g_strdup_printf(_("Invalid password or login. Please enter your %s login:"), rhbz->b_bugzilla_url);
|
|
- rhbz->b_login = ask_bz_login(question);
|
|
-
|
|
- free(rhbz->b_password);
|
|
- question = g_strdup_printf(_("Invalid password or login. Please enter the password for '%s':"), rhbz->b_login);
|
|
- rhbz->b_password = ask_bz_password(question);
|
|
- }
|
|
+ return api_key;
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
@@ -292,7 +270,7 @@ int main(int argc, char **argv)
|
|
"\nIf not specified, CONFFILE defaults to %1$s/plugins/bugzilla.conf"
|
|
"\nand user's local ~%2$s/bugzilla.conf."
|
|
"\nIts lines should have 'PARAM = VALUE' format."
|
|
- "\nRecognized string parameters: BugzillaURL, Login, Password, OSRelease."
|
|
+ "\nRecognized string parameters: BugzillaURL, BugzillaAPIKey, OSRelease."
|
|
"\nRecognized boolean parameter (VALUE should be 1/0, yes/no): SSLVerify."
|
|
"\nUser's local configuration overrides the system wide configuration."
|
|
"\nParameters can be overridden via $Bugzilla_PARAM environment variables."
|
|
@@ -464,18 +442,11 @@ int main(int argc, char **argv)
|
|
return EXIT_SUCCESS;
|
|
}
|
|
|
|
- if (rhbz.b_login[0] == '\0')
|
|
+ if (rhbz.b_api_key[0] == '\0')
|
|
{
|
|
- free(rhbz.b_login);
|
|
- g_autofree char *question = g_strdup_printf(_("Login is not provided by configuration. Please enter your %s login:"), rhbz.b_bugzilla_url);
|
|
- rhbz.b_login = ask_bz_login(question);
|
|
- }
|
|
-
|
|
- if (rhbz.b_password[0] == '\0')
|
|
- {
|
|
- free(rhbz.b_password);
|
|
- g_autofree char *question = g_strdup_printf(_("Password is not provided by configuration. Please enter the password for '%s':"), rhbz.b_login);
|
|
- rhbz.b_password = ask_bz_password(question);
|
|
+ free(rhbz.b_api_key);
|
|
+ g_autofree char *question = g_strdup_printf(_("API key is not provided by configuration. Please enter the API key for '%s':"), rhbz.b_bugzilla_url);
|
|
+ rhbz.b_api_key = ask_bz_api_key(question);
|
|
}
|
|
|
|
if (opts & OPT_t)
|
|
@@ -513,7 +484,7 @@ int main(int argc, char **argv)
|
|
log_warning(_("Using Bugzilla ID '%s'"), ticket_no);
|
|
}
|
|
|
|
- login(client, &rhbz);
|
|
+ rhbz_add_session_api_key(client, rhbz.b_api_key);
|
|
|
|
if (opts & OPT_w)
|
|
{
|
|
@@ -524,6 +495,8 @@ int main(int argc, char **argv)
|
|
ticket = (unsigned)ticket_intermediate;
|
|
else
|
|
error_msg_and_die("expected number in range <0, %d>: '%s'", UINT_MAX, ticket_no);
|
|
+ g_autofree char *question = g_strdup_printf(_("Please enter your %s login:"), rhbz.b_bugzilla_url);
|
|
+ rhbz.b_login = ask_bz_login(question);
|
|
rhbz_mail_to_cc(client, ticket, rhbz.b_login, /* require mail notify */ 0);
|
|
}
|
|
else
|
|
@@ -553,9 +526,6 @@ int main(int argc, char **argv)
|
|
}
|
|
}
|
|
|
|
- log_warning(_("Logging out"));
|
|
- rhbz_logout(client);
|
|
-
|
|
return 0;
|
|
}
|
|
|
|
@@ -639,8 +609,7 @@ int main(int argc, char **argv)
|
|
exit(0);
|
|
}
|
|
|
|
- login(client, &rhbz);
|
|
-
|
|
+ rhbz_add_session_api_key(client, rhbz.b_api_key);
|
|
|
|
unsigned long bug_id = 0;
|
|
|
|
@@ -745,9 +714,6 @@ int main(int argc, char **argv)
|
|
|
|
if (r == 0)
|
|
{
|
|
- log_warning(_("Logging out"));
|
|
- rhbz_logout(client);
|
|
-
|
|
exit(EXIT_CANCEL_BY_USER);
|
|
}
|
|
|
|
@@ -887,12 +853,14 @@ int main(int argc, char **argv)
|
|
* bug's status.
|
|
*/
|
|
|
|
- /* Add user's login to CC if not there already */
|
|
- if (strcmp(bz->bi_reporter, rhbz.b_login) != 0
|
|
- && !g_list_find_custom(bz->bi_cc_list, rhbz.b_login, (GCompareFunc)g_strcmp0)
|
|
- ) {
|
|
- log_warning(_("Adding %s to CC list"), rhbz.b_login);
|
|
- rhbz_mail_to_cc(client, bz->bi_id, rhbz.b_login, RHBZ_MINOR_UPDATE);
|
|
+ /* Add user's login to CC if not there already, but only if the login is known */
|
|
+ if (rhbz.b_login != NULL && rhbz.b_login[0] != '\0') {
|
|
+ if (strcmp(bz->bi_reporter, rhbz.b_login) != 0
|
|
+ && !g_list_find_custom(bz->bi_cc_list, rhbz.b_login, (GCompareFunc)g_strcmp0)
|
|
+ ) {
|
|
+ log_warning(_("Adding %s to CC list"), rhbz.b_login);
|
|
+ rhbz_mail_to_cc(client, bz->bi_id, rhbz.b_login, RHBZ_MINOR_UPDATE);
|
|
+ }
|
|
}
|
|
|
|
/* Add comment and bt */
|
|
@@ -947,9 +915,6 @@ int main(int argc, char **argv)
|
|
}
|
|
|
|
log_out:
|
|
- log_warning(_("Logging out"));
|
|
- rhbz_logout(client);
|
|
-
|
|
log_warning(_("Status: %s%s%s %s/show_bug.cgi?id=%u"),
|
|
bz->bi_status,
|
|
bz->bi_resolution ? " " : "",
|
|
diff --git a/src/plugins/rhbz.c b/src/plugins/rhbz.c
|
|
index c2855a70..5234250d 100644
|
|
--- a/src/plugins/rhbz.c
|
|
+++ b/src/plugins/rhbz.c
|
|
@@ -208,6 +208,21 @@ bool rhbz_login(struct abrt_xmlrpc *ax, const char *login, const char *password)
|
|
return true;
|
|
}
|
|
|
|
+
|
|
+bool rhbz_add_session_api_key(struct abrt_xmlrpc *ax, const char *api_key)
|
|
+{
|
|
+ func_entry();
|
|
+
|
|
+ xmlrpc_env env;
|
|
+ xmlrpc_env_init(&env);
|
|
+
|
|
+ log_debug("Adding session param Bugzilla_api_key");
|
|
+ abrt_xmlrpc_client_add_session_param_string(&env, ax, "Bugzilla_api_key", api_key);
|
|
+
|
|
+ return true;
|
|
+}
|
|
+
|
|
+
|
|
xmlrpc_value *rhbz_get_member(const char *member, xmlrpc_value *xml)
|
|
{
|
|
func_entry_str(member);
|
|
diff --git a/src/plugins/rhbz.h b/src/plugins/rhbz.h
|
|
index 7183da35..d10ff31c 100644
|
|
--- a/src/plugins/rhbz.h
|
|
+++ b/src/plugins/rhbz.h
|
|
@@ -67,6 +67,8 @@ void free_bug_info(struct bug_info *bz);
|
|
|
|
bool rhbz_login(struct abrt_xmlrpc *ax, const char *login, const char *password);
|
|
|
|
+bool rhbz_add_session_api_key(struct abrt_xmlrpc *ax, const char *api_key);
|
|
+
|
|
void rhbz_mail_to_cc(struct abrt_xmlrpc *ax, int bug_id, const char *mail, int flags);
|
|
|
|
void rhbz_add_comment(struct abrt_xmlrpc *ax, int bug_id, const char *comment,
|
|
diff --git a/tests/bugzilla_plugin.at.in b/tests/bugzilla_plugin.at.in
|
|
index abb912a0..0006ee92 100644
|
|
--- a/tests/bugzilla_plugin.at.in
|
|
+++ b/tests/bugzilla_plugin.at.in
|
|
@@ -37,13 +37,10 @@ TS_MAIN
|
|
TS_ASSERT_TRUE(conf->ec_supports_restricted_access);
|
|
|
|
event_option_t options[10] = {
|
|
- { .eo_value = NULL, .eo_label = (char *)"User name",
|
|
- .eo_note_html = (char *)"You can create bugzilla.redhat.com account <a href=\"https://bugzilla.redhat.com/createaccount.cgi\">here</a>",
|
|
+ { .eo_value = NULL, .eo_label = (char *)"API key",
|
|
+ .eo_note_html = (char *)"You can generate the API key for your Bugzilla account <a href=\"https://bugzilla.redhat.com/userprefs.cgi?tab=apikey\">here</a>",
|
|
.eo_type = OPTION_TYPE_TEXT, .eo_allow_empty = 0, .is_advanced = 0,
|
|
},
|
|
- { .eo_value = NULL, .eo_label = (char *)"Password", .eo_note_html = NULL,
|
|
- .eo_type = OPTION_TYPE_PASSWORD, .eo_allow_empty = 0, .is_advanced = 0,
|
|
- },
|
|
{ .eo_value = (char *)"@RED_HAT_BUGZILLA_CREATE_PRIVATE@", .eo_label = (char *)"Restrict access",
|
|
.eo_note_html = (char *)"Restrict access to the created bugzilla ticket allowing only users from specified groups to view it (see advanced settings for more details)",
|
|
.eo_type = OPTION_TYPE_BOOL, .eo_allow_empty = 0, .is_advanced = 0,
|
|
@@ -79,8 +76,7 @@ TS_MAIN
|
|
};
|
|
|
|
const char *option_names[] = {
|
|
- "Bugzilla_Login",
|
|
- "Bugzilla_Password",
|
|
+ "Bugzilla_APIKey",
|
|
"Bugzilla_CreatePrivate",
|
|
"Bugzilla_PrivateGroups",
|
|
"Bugzilla_BugzillaURL",
|
|
--
|
|
2.35.1
|
|
|