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(bitbucket-server): support bearer token authentication #26522

Closed
wants to merge 1 commit into from
Closed

feat(bitbucket-server): support bearer token authentication #26522

wants to merge 1 commit into from

Conversation

jaecktec
Copy link

@jaecktec jaecktec commented Jan 5, 2024

Add support for project/repository http access token

Changes

allowed token authentication by passing the authentication to the rest api and simple-git as extra-header

Context

fixes #14900

Documentation (please check one with an [x])

  • I have updated the documentation, or
  • No documentation update is required

How I've tested my work (please select one)

I have verified these changes via:

  • Code inspection only, or
  • Newly added/modified unit tests, or
  • No unit tests but ran on a real repository, or
  • Both unit tests + ran on a real repository

Add support for project/repository http access token
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@@ -302,7 +316,9 @@ export async function getPrList(refreshCache?: boolean): Promise<Pr[]> {
};
if (!config.ignorePrAuthor) {
searchParams['role.1'] = 'AUTHOR';
searchParams['username.1'] = config.username;
if(config.username){
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can the username be "learned" using the API? It's possible in other platforms to do a "whoami" type query to the API

Copy link
Author

Choose a reason for hiding this comment

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

no, afaik the point is to be anonymous. the tokens are for a repository and not for a user. They are no PAT.

Copy link
Member

Choose a reason for hiding this comment

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

please check what's the author for PRs created by such a token.

@@ -17,13 +17,16 @@ export function getNoVerify(): GitNoVerifyOption[] {
return noVerify;
}

export function simpleGitConfig(): Partial<SimpleGitOptions> {
export function simpleGitConfig(extraConfig: SimpleGitOptions['config'] = []): Partial<SimpleGitOptions> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't it possible to pass token in the same way other platforms do?

Copy link
Member

Choose a reason for hiding this comment

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

yes, revert

Copy link
Author

Choose a reason for hiding this comment

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

the token can't be passed as an URL argument

@@ -63,7 +63,7 @@ export const id = 'bitbucket-server';

let config: BbsConfig = {} as any;

const bitbucketServerHttp = new BitbucketServerHttp();
let bitbucketServerHttp: BitbucketServerHttp;
Copy link
Member

Choose a reason for hiding this comment

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

nope, revert

Comment on lines +97 to +106
let options: HttpOptions | undefined = undefined;
if (token) {
options = {
headers: {
'authorization': `Bearer ${token}`,
},
};
}

bitbucketServerHttp = new BitbucketServerHttp(options)
Copy link
Member

Choose a reason for hiding this comment

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

nope, revert. the check above should be enough to allow token auth , because the token is later converted to hostrule and then implicit used for bearer auth.

@@ -205,6 +218,7 @@ export async function initRepo({
url,
cloneSubmodules,
fullClone: true,
authorization: opts.token,
Copy link
Member

Choose a reason for hiding this comment

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

no, will already be handled via hostrule and is already added to opts.

you need to update the getRepoGitUrl function above to handle token auth.

@@ -17,13 +17,16 @@ export function getNoVerify(): GitNoVerifyOption[] {
return noVerify;
}

export function simpleGitConfig(): Partial<SimpleGitOptions> {
export function simpleGitConfig(extraConfig: SimpleGitOptions['config'] = []): Partial<SimpleGitOptions> {
Copy link
Member

Choose a reason for hiding this comment

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

yes, revert

@@ -232,7 +232,7 @@ export async function initRepo(args: StorageConfig): Promise<void> {
config.ignoredAuthors = [];
config.additionalBranches = [];
config.branchIsModified = {};
git = simpleGit(GlobalConfig.get('localDir'), simpleGitConfig()).env({
git = simpleGit(GlobalConfig.get('localDir'), simpleGitConfig(config.authorization ? [`http.extraHeader=Authorization: Bearer ${config.authorization}`] : undefined)).env({
Copy link
Member

Choose a reason for hiding this comment

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

revert

@@ -17,6 +17,7 @@ export type LongCommitSha = string & { __longCommitSha: never };
export interface StorageConfig {
currentBranch?: string;
url: string;
authorization?: string,
Copy link
Member

Choose a reason for hiding this comment

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

revert.

Comment on lines +26 to +29
config: [
...extraConfig,
'core.quotePath=false',
],
Copy link
Member

Choose a reason for hiding this comment

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

revert

@jaecktec jaecktec closed this Jan 8, 2024
@jaecktec jaecktec deleted the improvement/bibucket-server-repo-access-token branch January 8, 2024 07:37
@simschla
Copy link

simschla commented Jan 9, 2024

I'm confused: is this PR closed because the feature will not be added or is it not possible?

@viceice
Copy link
Member

viceice commented Jan 15, 2024

it seems the author is not able to implement the suggestions or can't sign the cla

@jaecktec
Copy link
Author

jaecktec commented Jan 22, 2024

I can't find the suggested places required to be changed.
And most of the changes had the 'revert' comment, so basically the entire PR

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Authorization type of "Bearer <token>" for Bitbucket Server
5 participants