The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

To create a pre-receive hook in bitbucket for securing the AWS access keys and secret keys

Sravan Kumar
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 15, 2018

create a hook where it should restricts

  • AWS IAM roles and policies do not grant permissive permissions (Least-privilege access by default)
  • Secrets (private keys, system passwords, cloud access keys, etc.) are not embedded in code

I believe where i need to write custom script to invoke the notifications before i push code to bitbucket 

can anyone guide me in writing the script..?

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
preygil2
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 9, 2019

something like this for "secrets"

 

public class ExampleHook implements PreRepositoryHook<RepositoryHookRequest> {
 
    private ScmService scmService;


    public ExampleHook(@ComponentImport final ScmService scmService) {

        this.scmService = scmService; // injecting ScmService dependency
    }
    
    @Nonnull
    @Override
    public RepositoryHookResult preUpdate(@Nonnull PreRepositoryHookContext context,
                                          @Nonnull RepositoryHookRequest request) {
        request.getRefChanges().stream()
       .forEach(refChange -> scmService.getBulkContentCommandFactory(request.getRepository())
               .contents(new BulkContentCommandParameters.Builder(refChange.getToHash())
                       .sinceCommitId(refChange.getFromHash())
                       .build(), new BulkContentCallback() {
                               @Override
                               public void onFile(@Nonnull BulkFile file, @Nonnull InputStream content) {
                                    // check InputStream for patterns that you want to avoid
                                  // if found return RepositoryHookResult.rejected();
                               }
          }).call());
                
          return RepositoryHookResult.accepted();
    }

}

TAGS
AUG Leaders

Atlassian Community Events