Skip to content

Commit 5904bac

Browse files
authored
Use Jira Personal Access Token (PAT) (#1389)
use Jira Personal Access Token (PAT) for release scripts to address expired service account token
1 parent eec6bd4 commit 5904bac

File tree

2 files changed

+12
-48
lines changed

2 files changed

+12
-48
lines changed

etc/make_release.py

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
from git import Repo # pip install GitPython
5252
from github import Github # pip install PyGithub
5353
from jira import JIRA # pip install jira
54-
import oauthlib.oauth1
5554

5655
if sys.version_info < (3, 0, 0):
5756
raise RuntimeError("This script requires Python 3 or higher")
@@ -72,11 +71,11 @@
7271
@click.option('--skip-release-tag',
7372
is_flag=True,
7473
help='Use an existing release tag instead of creating a new one')
75-
@click.option('--jira-creds-file',
74+
@click.option('--jira-token-file',
7675
'-j',
77-
default='jira_creds.txt',
76+
default='jira_token.txt',
7877
show_default=True,
79-
help='Jira OAuth credentials file')
78+
help='Jira token file. Contains a Personal Access Token. See https://wiki.corp.mongodb.com/spaces/TOGETHER/pages/218995581/Jira+Personal+Access+Tokens+PATs')
8079
@click.option('--github-token-file',
8180
'-g',
8281
default='github_token.txt',
@@ -116,7 +115,7 @@
116115
@click.argument('git-revision', required=True)
117116
# pylint: disable=too-many-arguments,too-many-locals,too-many-branches,too-many-statements
118117
def release(skip_release_tag,
119-
jira_creds_file,
118+
jira_token_file,
120119
github_token_file,
121120
allow_open_issues,
122121
remote,
@@ -137,8 +136,8 @@ def release(skip_release_tag,
137136
# Read Jira credentials and GitHub token first, to check that
138137
# user has proper credentials before embarking on lengthy builds.
139138
jira_options = {'server': 'https://jira.mongodb.org'}
140-
jira_oauth_dict = read_jira_oauth_creds(jira_creds_file)
141-
auth_jira = JIRA(jira_options, oauth=jira_oauth_dict)
139+
jira_token = pathlib.Path(jira_token_file).read_text().rstrip()
140+
auth_jira = JIRA(jira_options, token_auth=jira_token)
142141

143142
github_token = read_github_creds(github_token_file)
144143
auth_gh = Github(github_token)
@@ -468,36 +467,6 @@ def build_distribution(release_tag, release_version, c_driver_dir, quiet, skip_d
468467
run_shell_script('cmake --build build --target distcheck')
469468
return dist_file
470469

471-
def read_jira_oauth_creds(jira_creds_file):
472-
"""
473-
Read the Jira Oauth credentials file and return a dictionary containing the
474-
credentials.
475-
"""
476-
477-
creds_re = re.compile(
478-
r'^[\s\S]*access_token\s*:\s*(\S+)\s*'
479-
r'access_token_secret\s*:\s*(\S+)\s*'
480-
r'consumer_key\s*:\s*(\S+)\s*'
481-
r'key_cert\s*:\s*(-.*-)[\s\S]*$')
482-
483-
oauth_dict = {}
484-
with open(jira_creds_file, 'rb') as creds_stream:
485-
creds_data = creds_stream.read().decode('ascii')
486-
creds_match = creds_re.match(creds_data)
487-
if creds_match:
488-
oauth_dict['access_token'] = creds_match.group(1)
489-
oauth_dict['access_token_secret'] = creds_match.group(2)
490-
oauth_dict['consumer_key'] = creds_match.group(3)
491-
# Fix the double-backslash created by the decode() call above
492-
oauth_dict['key_cert'] = creds_match.group(4).replace("\\n", "\n")
493-
# Use signature algorithm `SIGNATURE_RSA` to override `jira` default of `SIGNATURE_HMAC_SHA1`.
494-
# `jira` 3.5.1 changed the default signature algorithm to `SIGNATURE_HMAC_SHA1`.
495-
# MongoDB Jira servers do not appear to support `SIGNATURE_HMAC_SHA1`. Using `SIGNATURE_HMAC_SHA1` results in `signature_method_rejected`` error.
496-
# See https://github.com/pycontribs/jira/pull/1664
497-
oauth_dict["signature_method"] = oauthlib.oauth1.SIGNATURE_RSA
498-
499-
return oauth_dict
500-
501470
def get_jira_project_versions(auth_jira):
502471
"""
503472
Return a dictionary of release versions available in the Jira project.

etc/releasing.md

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,13 @@ Some release steps require one or more of the following secrets.
4848
(classic) token with the "repo" scope selected.
4949
5050
Configure SSO to authorize this token for the `mongodb` organization. (Do not forget this step!)
51-
- Jira OAuth credentials.
52-
- Location: `~/.secrets/jira-creds.txt`
51+
- A Jira Personal Access Token (PAT)
52+
- Location: `~/.secrets/jira-token.txt`
5353
- Format:
5454
```
55-
56-
57-
access_token : <access_token>
58-
access_token_secret : <access_token_secret>
59-
consumer_key : <consumer_key>
60-
key_cert: -----BEGIN RSA PRIVATE KEY-----\n...\n-----END RSA PRIVATE KEY-----
55+
<jira_token>
6156
```
62-
Note the `"\n"` strings must be preserved as-is in the key_cert value.
57+
- See [Jira: Personal Access Tokens (PATs)](https://wiki.corp.mongodb.com/spaces/TOGETHER/pages/218995581/Jira+Personal+Access+Tokens+PATs) for steps to create a token.
6358
- Artifactory credentials.
6459
- Location: `~/.secrets/artifactory-creds.txt`:
6560
- Format:
@@ -326,7 +321,7 @@ python ./etc/make_release.py --help
326321
The following secrets are required by this script:
327322

328323
- GitHub Personal Access Token.
329-
- Jira OAuth credentials.
324+
- Jira Personal Access Token.
330325
- Artifactory credentials.
331326
- Garasign credentials.
332327

@@ -336,7 +331,7 @@ Run the release script with the name of the tag to be created as an argument and
336331
```bash
337332
make_release_args=(
338333
-r upstream
339-
--jira-creds-file ~/.secrets/jira-creds.txt
334+
--jira-token-file ~/.secrets/jira-token.txt
340335
--github-token-file ~/.secrets/github-token.txt
341336
)
342337
python ./etc/make_release.py "${make_release_args[@]:?}" --dry-run rX.Y.Z

0 commit comments

Comments
 (0)