# Access denied when microservice tries to retrieve encrypted tenant option

**URL:** <https://community.cumulocity.com/t/access-denied-when-microservice-tries-to-retrieve-encrypted-tenant-option/7421>\
**Category:** Forum\
**Tags:** cumulocity\
**Created:** [October 9, 2023, 4:38pm UTC](https://community.cumulocity.com/t/access-denied-when-microservice-tries-to-retrieve-encrypted-tenant-option/7421 "2023-10-09T16:38:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tse\_xuan.ngiam](https://avatars.discourse-cdn.com/v4/letter/t/6a8cbe/32.png) [@tse\_xuan.ngiam](https://community.cumulocity.com/u/tse_xuan.ngiam)\
**Post date:** [October 9, 2023, 4:38pm UTC](https://community.cumulocity.com/t/access-denied-when-microservice-tries-to-retrieve-encrypted-tenant-option/7421/1 "2023-10-09T16:38:18Z")

</div>

#### _ **Product/components** used and **version/fix** level:_

Cumulocity version 1018.0.125 (frontend) 1018.0.174 (backend)

#### _Detailed explanation of the problem:_

From the guide [[Cumulocity IoT - OpenAPI Specification](https://cumulocity.com/api/core/10.17.0/#operation/postOptionCollectionResource)]([https://cumulocity.com/api/core/10.17.0/#operation/postOptionCollectionResource](https://cumulocity.com/api/core/10.17.0/#operation/postOptionCollectionResource)) I learned that encrypted option cannot be received by regular user (I tried and it returns {“self”:“https:xxxx.cumulocity.com/tenant/options/secrets/credentials.test\_key”,“category”:“secrets”,“value”:“\<\>”,“key”:“credentials.test\_key”}) but when it is sent to a microservice, the value should be decrypted.  
However, when sending GET request from my microservice to retrieve the option, it returns {“message”:“Access is denied”,“error”:“security/Forbidden”,“info”:…}

## Here is how I formulate the request:

```auto
def base64_credentials(tenant, user, password):
    str_credentials = tenant + "/" + user + ":" + password
    return 'Basic ' + base64.b64encode(str_credentials.encode()).decode()
def sample_get_token:
        url = https:xxxx.cumulocity.com/tenant/options/secrets/credentials.test_key
        payload = {}
        headers = {
             'Authorization': base64_credentials(os.getenv('C8Y_BOOTSTRAP_TENANT'), os.getenv('C8Y_BOOTSTRAP_USER'), os.getenv('C8Y_BOOTSTRAP_PASSWORD'))
        }
        response = requests.request("GET", url, headers=headers, data=payload)
        private_key = json.loads(response.text)["value"]

```

#### _Error messages / **full error** message screenshot / **log** file:_

KeyError, as response == {“message”:“Access is denied”,“error”:“security/Forbidden”,“info”:…}

#### _Question related to a **free trial** , or to a **production (customer)** instance?_

This is a production instance

---

<div class="post-metadata">

**Author:** ![Christian\_Guether1](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/christian_guether1/32/14848_2.png) [@Christian\_Guether1](https://community.cumulocity.com/u/Christian_Guether1)\
**Post date:** [October 10, 2023, 5:55am UTC](https://community.cumulocity.com/t/access-denied-when-microservice-tries-to-retrieve-encrypted-tenant-option/7421/2 "2023-10-10T05:55:45Z")

</div>

Hi,

your Microservice needs the necessary roles to access the Tenant Option API. If your Microservice wants to read options, it must define `"ROLE_OPTION_MANAGEMENT_READ"` as a required role in its `cumulocity.json`. In case the Microservice needs to write tenant options, it must specify the required role `"ROLE_OPTION_MANAGEMENT_ADMIN"`.

Best regards

  

* * *

Christian Guether

[Software AG Professional Services](https://www.softwareag.com/en_corporate/resources/services/professional-services.html)

[![](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/c/3/c3a93a2618e4708f51be40fe2e142061f7c4edc7.jpeg)](https://www.softwareag.com/en_corporate/resources/services/fast-track-services.html)

---

<div class="post-metadata">

**Author:** ![Tristan\_Bastian](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/tristan_bastian/32/18259_2.png) [@Tristan\_Bastian](https://community.cumulocity.com/u/Tristan_Bastian)\
**Post date:** [October 10, 2023, 7:32am UTC](https://community.cumulocity.com/t/access-denied-when-microservice-tries-to-retrieve-encrypted-tenant-option/7421/3 "2023-10-10T07:32:55Z")

</div>

It also seems you are using the wrong credentials.  
The `C8Y_BOOTSTRAP` prefixed credentials are meant to be used to retrieve the subscriptions of the microservice (actual service credentials for every subscribed tenant), see: [General aspects - Cumulocity IoT Guides](https://cumulocity.com/guides/microservice-sdk/concept/#microservice-bootstrap) They are not meant to access the other Cumulocity APIs.  
If you have a per tenant scoped microservice, you could use `C8Y_TENANT`, `C8Y_USER`, `C8Y_PASSWORD` instead.

---

<div class="post-metadata">

**Author:** ![tse\_xuan.ngiam](https://avatars.discourse-cdn.com/v4/letter/t/6a8cbe/32.png) [@tse\_xuan.ngiam](https://community.cumulocity.com/u/tse_xuan.ngiam)\
**Post date:** [October 10, 2023, 10:20am UTC](https://community.cumulocity.com/t/access-denied-when-microservice-tries-to-retrieve-encrypted-tenant-option/7421/4 "2023-10-10T10:20:08Z")

</div>

Thank you, it works after defining the role and using the service user’s credential as suggested by @Tristan_Bastian . I referred to the sample script (just search cumulocity microservices/sample-python-microservice, sorry that I cannot include links in my post) for this case

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/system/32/31990_2.png) [@system](https://community.cumulocity.com/u/system)\
**Post date:** [April 7, 2024, 10:20am UTC](https://community.cumulocity.com/t/access-denied-when-microservice-tries-to-retrieve-encrypted-tenant-option/7421/5 "2024-04-07T10:20:51Z")

</div>

Closed on April 7, 2024, 10:20am UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
