# Access to metadata in policy

**URL:** <https://discuss.hashicorp.com/t/access-to-metadata-in-policy/54694>\
**Category:** Vault\
**Created:** [June 7, 2023, 4:41pm UTC](https://discuss.hashicorp.com/t/access-to-metadata-in-policy/54694 "2023-06-07T16:41:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hypolas](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/hypolas/32/36142_2.png) [@hypolas](https://discuss.hashicorp.com/u/hypolas)\
**Post date:** [June 7, 2023, 4:41pm UTC](https://discuss.hashicorp.com/t/access-to-metadata-in-policy/54694/1 "2023-06-07T16:41:35Z")

</div>

Hello,

I would like some help. I try to create this architecture:  
token =\> alias =\> entity =\> policies =\> kv

The first step seeams be ok (token =\> alias =\> entity). But I have e problème with policies. I want template policies like this:

```auto
path "client_kv/data/{{ identity.entity.metadata.service_name }}/*" {
  capabilities = ["read", "list"]
}

```

service\_name is a metadata in entity but that not work. Do you have e suggestion ?

Here, a part of my code:

```auto
func (v *VClient) createEntity(service string) (canonI string) {
	// Create or Get entity ID
	log.Println("Created or get info entitie for =>", service)
	entitieName := "entitie_customer_" + service
	var canonId string
	if _, ok := v.EntitiesList[entitieName]; ok {
		entitie, _ := v.vaultClient.Identity.EntityReadByName(v.ctx, entitieName)
		canonId = entitie.Data["id"].(string)
	} else {
		result, err := v.vaultClient.Identity.EntityCreate(v.ctx, schema.EntityCreateRequest{
			Name: entitieName,
			Metadata: map[string]interface{}{"service_name": service, "type": "entitie"},
			Policies: []string{"customer_default", "default"},
		})
		if err != nil {
			panic(err)
		}
		v.EntitiesList[entitieName] = true
		canonId = result.Data["id"].(string)
	}
	return canonId
}

func (v *VClient) createAlias(service, canonId string) {
	log.Println("Created alias for =>", service)
	_, err := v.vaultClient.Identity.EntityCreateAlias(v.ctx, schema.EntityCreateAliasRequest{
		Name: "alias_" + service,
		CanonicalId: canonId,
		MountAccessor: santeclair_kv_accessor,
		CustomMetadata: map[string]interface{}{"service_name": service, "type": "alias"},
	})

	if err != nil {
		panic(err)
	}
}

```

Best regards,  
Nicolas
