Getting a 403 - permission denied when using aws client to set the acl to public-read - ibm-cloud

I am attempting to change the asl of a file (100KB.file) I have within IBM COS: bucket: 'devtest1.ctl-internal.nasv.cos' and am receiving the following message:
An error occurred (AccessDenied) when calling the PutObjectAcl
operation: Access Denied
It seems like my AWS credentials (or call) do not have the correct permissions to allow the ACL update.
Command:
aws --endpoint-url=https://s3.us-south.objectstorage.softlayer.net
s3api put-object-acl --bucket devtest1.ctl-internal.nasv.cos --key
100KB.file --acl public-read
Return:
An error occurred (AccessDenied) when calling the PutObjectAcl
operation: Access Denied

You haven’t mentioned that you have configured hmac credentials on your bucket, so I’ll assume you haven't. I'm also assuming that operations other than PutObjectAcl do not work for you.
Try adding hmac credentials:
Then ...
Source: https://console.bluemix.net/docs/services/cloud-object-storage/hmac/credentials.html#using-hmac-credentials

I am having the same issue as well using the AWS CLI. However, you can do the same operation using cURL and providing your IBM Cloud IAM token.
curl -X "PUT" "https://{endpoint}/{bucket-name}/{object-name}?acl" \
-H "x-amz-acl: public-read" \
-H "Authorization: Bearer {token}" \
-H "Content-Type: text/plain; charset=utf-8" \

Related

How to self revoke token via vault api?

When i try to revoke a self token using api method i'm getting permission denied error
curl -H "X-Vault-Token: s.XXXXXXXXXXXXXXYYYYYYYYYYYY" -X GET $VAULT_ADDR/v1/auth/token/revoke-self
{"errors":["1 error occurred:\n\t* permission denied\n\n"]}
But if i login using same token and try via cli it is working as expected
$ vault token revoke -self
Success! Revoked token (if it existed)
Is it working as expected? or am i trying to use in a wrong way?
Use the "POST" request instead of the "GET" one:
curl -H "X-Vault-Token: s.XXXXXXXXXXXXXXYYYYYYYYYYYY" -X POST $VAULT_ADDR/v1/auth/token/revoke-self

Gcloud error 401: REquest had invalid authentication credentials

I'm working on a project where I need to access a Gcloud service account. However, I've been encountering issues with authentication. This is the following error from my command prompt:
My command:
curl -s -H "Content-Type: application/json" \
-H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
https://speech.googleapis.com/v1/speech:recognize \
-d #sync-request.json
Output:
{
"error": {
"code": 401,
"message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"status": "UNAUTHENTICATED"
}
}
At the current moment, I have done the following: I set my environment variable, "GOOGLE_APPLICATION_CREDENTIALS", to hold the path to my service account's JSON key file, I opened my cmd in the directory where the key file is located, I ran the command. Is there anything else I'm missing?
The documentation I am following is from https://cloud.google.com/docs/authentication/production#windows
Couple of things.
gcloud does not use ADC; setting GOOGLE_APPLICATION_CREDENTIALS does not configure gcloud.
You should (have not tried) be able to use gcloud auth activate-service-account ... and then gcloud auth print-access-token.
Or you can just use a regular (human|non-service) account and gcloud auth print-access-token.
Or, you can use gcloud auth application-default login and then gcloud auth application-default print-access-token but the two go together.
Don't quote the token in header:
TOKEN="$(gcloud auth print-access-token)" # Either
TOKEN="$(gcloud auth application-default print-access-token)" # Or
curl \
--silent \
--header "Content-Type: application/json" \
--header "Authorization: Bearer ${TOKEN}" \
--data #sync-request.json \
https://speech.googleapis.com/v1/speech:recognize

PCF p-config-server /decrypt api returning 403 forbidden error

While trying to use encryption/decryption feature of spring cloud config server with Pivotal Cloud Foundry's p-config-server service which is configured with a symmetric key for encryption, I am getting a 403 forbidden response which calling /decrypt on config server .
I am able to call the /encrypt endpoint successfully for encrypting values using below sample curl -
curl --location --request POST 'https://config-xxxx.apps.xxx.com/encrypt' \
--header 'Authorization: bearer <cf oauth_token here>' \
--header 'Content-Type: text/plain' \
--data-raw 'sample data'
But when trying to decrypt those values using /decrypt, I am getting 403 Forbidden error -
{
"error": "access_denied",
"error_description": "invalid issuer"
}
Sample curl for decryption -
curl --location --request POST 'https://config-xxxx.apps.xxx.com/decrypt' \
--header 'Authorization: bearer <cf oauth_token here>' \
--header 'Content-Type: text/plain' \
--data-raw '<encrypted value from previous step>'
In pivotal's config server documentation though there are reference to /encrypt but nothing related to /decrypt pivotal config server
Any pointers ?
In the Pivotal/Tanzu Spring Cloud Services (commercial product), the /encrypt API is exposed to anyone with the admin scope or to anyone that is a Space Developer in the space of the service.
The /decrypt endpoint is not exposed specifically, so you're not allowed to access with the same credentials, hence why you're seeing a 403.
My quick read of the code is that you'd need a token with scope config_server_<guide>.read to access that endpoint. Where <guid> is the config server's service guide (run cf service --guid <name> to obtain the guide).
To make that work, you'd need to get a token from the bound service or a service key, the latter is easier:
Run cf create-service-key <service_instance> decrypt-key
Run cf service-key <service_instance> decrypt-key
Run export TOKEN=$(curl -vv <access_token_uri> -d 'grant_type=client_credentials' -d 'client_id=<client_id>' -d 'client_secret=<client_secret>' | jq -r .access_token) where the values in <...> are from the output of #2.
Run curl -vv '<uri>/decrypt' -H "Authorization: bearer $TOKEN" -H 'Content-type: text/plain' -d '<encrypted-value>'
These depend on a Bash shell. You can do them on Windows, but the commands will vary. It also uses jq to make extracting the token easier. You could split the command in step #3 into two steps, fetching with curl and manually exporting TOKEN.

How to access IBM logDNA without going through ibm-console login

I'm trying to access IBM provided logDNA without logging in IBM console and traversing to LogDNA Dashboard location
I've no clue on how to proceed with this.
curl "https://logs.logdna.com/logs/ingest?hostname=EXAMPLE_HOST&mac=C0:FF:EE:C0:FF:EE&ip=10.0.1.101&now=$(date +%s)" \
-u INSERT_INGESTION_KEY: \
-H "Content-Type: application/json; charset=UTF-8" \
-d \
'{
"lines": [
{
"line":"This is an awesome log statement",
"app":"myapp",
"level": "INFO",
"env": "production",
"meta": {
"customfield": {
"nestedfield": "nestedvalue"
}
}
}
]
}'
In the above code snippet the URL used is generic URL, instead of that I want to generate a URL for my IBM LogDNA which should be accessible through access token, so that I can use below type code snippet to push the logs to logDNA directly from the code.
Currently to open LogDNA dashboard, I login to IBM cloud UI and check in Observability section.
Is there a way we can access this through tokens and have a custom URL on which I can apply this?
The steps to obtain the dashboard URL using the command line are described in the related IBM Cloud Logging service documentation.
This works for the Activity Tracker the same way:
$ ibmcloud resource service-instance your-instance-name --output json | jq -r '.[0].dashboard_url'
LogDNA documentation about REST ingestion is amazing...
But their service is really amazing. And this works for me:
In LogDNA dashboard, at [Settings -> Organization -> API Keys] you can find your key.
Let's say, you key is 77777haha77777777777hoho.
In you curl command replace the second row with this:
-u "77777haha77777777777hoho:77777haha77777777777hoho" \
Entire tested command:
curl "https://logs.logdna.com/logs/ingest?
hostname=EXAMPLE_HOST&mac=C0:FF:EE:C0:FF:EE&ip=10.0.1.101&now=1610830847530" \
-u "77777haha77777777777hoho:77777haha77777777777hoho" \
-H "Content-Type: application/json; charset=UTF-8" \
-d \
'{
"lines":[
{
"timestamp":1610830847530,
"line":"This is an awesome log statement",
"file":"example.log"
}
]
}'

Upload SSH public key to bitbucket cloud using curl/REST and token

I have a bitbucket cloud account. Under: https://id.atlassian.com/manage/api-tokens I have generated an API Token which I am trying to use in a REST call to upload
a public SSH key to my account. Based on:
https://docs.atlassian.com/bitbucket-server/rest/5.6.2/bitbucket-ssh-rest.html?utm_source=%2Fstatic%2Frest%2Fbitbucket-server%2F5.6.2%2Fbitbucket-ssh-rest.html&utm_medium=301#idm45427244388592
https://community.atlassian.com/t5/Answers-Developer-Questions/Bitbucket-REST-API-POST-using-token-instead-of-basic-auth/qaq-p/474823
I have tried:
curl -X POST -d '{"text":"ssh-rsa AAAAB3... me#127.0.0.1"}' -H "Authorization: Bearer ADasdaEeasAsd..." https://bitbucket.org/[my-account]]/rest/ssh/latest/keys
But when I run that I get:
{"type": "error", "error": {"message": "Access token expired. Use your refresh token to obtain a new access token."}}
I have tried to re-create the token and re-run the above command again - with the new token - but I get the same error.
Any suggestions?
Based on below answer and link I have now tried:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer wxdrtblabla..." \
-d '{"key": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKqP3Cr632C2dNhhgKVcon4ldUSAeKiku2yP9O9/bDtY myuser#bitbucket.org/myuser"}' \
https://api.bitbucket.org/2.0/users/myuser/ssh-keys
But I get the exact same error:
{"type": "error", "error": {"message": "Access token expired. Use your refresh token to obtain a new access token."}}
So still no luck. Also if I access:
https://api.bitbucket.org/2.0/users/[myuser]/ssh-keys
directly in a browser I get:
type "error"
error
message "This API is only accessible with the following authentication types: session, password, apppassword"
EDIT/ANSWERED: Based on the updated answer below I have no tried to create an app password and grant it account: read/write in bitbucket and it works. I run it with:
curl -v -u myuser:my-generated-app-password -X POST \
-H "Content-Type: application/json" \
-d '{"key": "ssh-rsa AAA....ro"}' \
https://api.bitbucket.org/2.0/users/myuser/ssh-keys
You're looking at Bitbucket Server documentation but using Bitbucket Cloud. (The giveaways: the "bitbucket-server" part of the doc path, and the "bitbucket.org" in the path where you're pushing your key.)
Check out https://developer.atlassian.com/bitbucket/api/2/reference/resource/users/%7Busername%7D/ssh-keys#post instead - that's the Bitbucket Cloud documentation to do what you're trying to do. Your URL will be more like https://api.bitbucket.org/2.0/users/[your-account]/ssh-keys.
EDIT: The error you received indicates the problem: you either need to make that call from within an existing session (i.e. from the GUI), use your password, or use an app password. I'd recommend the app password, since it's scoped, meant to be disposable, and won't let you log onto the GUI. Your curl call then becomes something like curl -u myuser:myapppassword -X POST -H "Content-Type: application/json" -d '{"key": "key content goes here"}' https://api.bitbucket.org/2.0/users/myuser/ssh-keys.