Using curl POST request to import file from S3 bucket to Git

0

Hi I'm new to AWS, and I've been trying to upload a repository to an S3 bucket and use it to import this repository to GitLab, using their documentation. The bucket isn't publicly accessible, and I've created an access point and token for my user. The code suggested is:

>curl --request POST "https://gitlab.com/api/v4/projects/remote-import-s3"
 --header "PRIVATE-TOKEN:**MYTOKEN**" --header 'Content-Type:application/json'
 --data "name":"**NAME**","path":"https://gitlab.com/PATH","region":"**REGION NAME**",
"bucket_name":"**BUCKET NAME**","file_key":"**FILE KEY**","access_key_id":"********","secret_access_key":"********"

I also filled in the details needed, which I removed from the code above. When running this code in cmd I get the error: {"error":"region is missing, bucket_name is missing, file_key is missing, access_key_id is missing, secret_access_key is missing, path is missing"}.

What am I missing? Should I configure the bucket in a certain way? Allow some public access?

2 Answers
0

Hi, Thanks for helping out!

I've tried:

--data '{  
    "name":"**NAME**",
    "path":"https://gitlab.com/PATH",
    "region":"**REGION NAME**",
    "bucket_name":"**BUCKET NAME**",
    "file_key":"**FILE KEY**",
    "access_key_id":"********",
    "secret_access_key":"********" 
}'

but got an error, then I tried " double quotes and followed the errors until i finally got to run the command:

curl -v --request --url "https://gitlab.com/api/v4/projects/remote-import-s3" --header "PRIVATE-TOKEN: ******" 
--header "Content-Type: application/json" --data '{ "name": "****", "path": "https://gitlab.com/******", 
"region": "eu-north-1", "bucket_name": "*****", "file_key": "******", "access_key_id": "******", 
"secret_access_key": "*********" }'

Now I have this error:

*   Trying 172.65.251.78:443...
* Connected to gitlab.com (172.65.251.78) port 443 (#0)
* schannel: disabled automatic use of client certificate
* ALPN: offers http/1.1
* ALPN: server accepted http/1.1
* using HTTP/1.1
> --url /api/v4/projects/remote-import-s3 HTTP/1.1
> Host: gitlab.com
> User-Agent: curl/8.0.1
> Accept: */*
> PRIVATE-TOKEN: ********
> Content-Type: application/json
> Content-Length: 2
>
* schannel: server closed the connection
< HTTP/1.1 400 Bad Request
< Server: cloudflare
< Date: Tue, 18 Jul 2023 14:20:51 GMT
< Content-Type: text/html
< Content-Length: 155
< Connection: close
< CF-RAY: -
<
<html>
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<hr><center>cloudflare</center>
</body>
</html>
* Closing connection 0
* schannel: shutting down SSL/TLS connection with gitlab.com port 443
* Closing connection -1
curl: (3) URL using bad/illegal format or missing URL
* Closing connection -1
curl: (3) URL using bad/illegal format or missing URL
* Closing connection -1
curl: (3) URL using bad/illegal format or missing URL
* Hostname gitlab.com was found in DNS cache
*   Trying 172.65.251.78:443...
* Connected to gitlab.com (172.65.251.78) port 443 (#1)
* ALPN: offers http/1.1
* ALPN: server accepted http/1.1
* using HTTP/1.1
> --url /envitechsoftware/envitech_web/maintain-view, HTTP/1.1
> Host: gitlab.com
> User-Agent: curl/8.0.1
> Accept: */*
> PRIVATE-TOKEN: *******
> Content-Type: application/json
> Content-Length: 2
>
* schannel: server closed the connection
< HTTP/1.1 400 Bad Request
< Server: cloudflare
< Date: Tue, 18 Jul 2023 14:20:51 GMT
< Content-Type: text/html
< Content-Length: 155
< Connection: close
< CF-RAY: -
<
<html>
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<hr><center>cloudflare</center>
</body>
</html>
* Closing connection 1
* schannel: shutting down SSL/TLS connection with gitlab.com port 443
* Closing connection -1
curl: (3) URL using bad/illegal format or missing URL
* Closing connection -1
curl: (3) URL using bad/illegal format or missing URL
* Closing connection -1
curl: (3) URL using bad/illegal format or missing URL
* Closing connection -1
curl: (3) URL using bad/illegal format or missing URL
* Closing connection -1
curl: (3) URL using bad/illegal format or missing URL
* Closing connection -1
curl: (3) URL using bad/illegal format or missing URL
* Closing connection -1
curl: (3) URL using bad/illegal format or missing URL
* Closing connection -1
curl: (3) URL using bad/illegal format or missing URL
* Closing connection -1
curl: (3) URL using bad/illegal format or missing URL
* Could not resolve host: ******
* Closing connection 2
curl: (6) Could not resolve host: *******
curl: (3) unmatched close brace/bracket in URL position 1:
}'
 ^

The 2 rows mentioning "Could not resolve host: *******" refers to the content of "secret_access_key".

I'm sorry it took a while to responding, i was sick and away, I appreciate the help!

Eran
answered 9 months ago
  • Any special characters in the Secret Key that is throwing off the shell interpreter?

  • no. I managed to run the command through Git Bash instead of CMD and it worked, but it couldn't find the project. are there any special permissions I need to create? I'm a root user, opened a S3 bucket, added an access key, and uploaded the project. am I missing something?

  • Not sure at this point what the issue is. But, please, please, do not use AWS root user access keys for this this operation. Create an IAM user with a least-privilege policy for the S3 bucket and use the IAM access keys. Please delete the root user access keys ASAP.

0

It looks like you are missing the opening and closing brackets {} for --data.

--data '{ 
    "name":"**NAME**",
    "path":"https://gitlab.com/PATH",
    "region":"**REGION NAME**",
    "bucket_name":"**BUCKET NAME**",
    "file_key":"**FILE KEY**",
    "access_key_id":"********",
    "secret_access_key":"********" 
}'

https://gitlab.com/gitlab-org/gitlab/-/merge_requests/77259

profile pictureAWS
EXPERT
kentrad
answered 10 months ago
  • Hi! I had to comment as a separate answer because of the code. Please follow below. Thanks!

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions