<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: KBY Technologies</title>
    <description>The latest articles on DEV Community by KBY Technologies (@kbytech).</description>
    <link>https://dev.to/kbytech</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4032449%2Fea38ac73-b28c-42d8-9471-c5fd39f8bc43.png</url>
      <title>DEV Community: KBY Technologies</title>
      <link>https://dev.to/kbytech</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kbytech"/>
    <language>en</language>
    <item>
      <title>Removing identity From EncryptionConfiguration Before Secrets Are Rewritten Makes Plaintext Secrets Unreadable</title>
      <dc:creator>KBY Technologies</dc:creator>
      <pubDate>Tue, 01 Dec 2026 15:11:14 +0000</pubDate>
      <link>https://dev.to/kbytech/removing-identity-from-encryptionconfiguration-before-secrets-are-rewritten-makes-plaintext-secrets-en2</link>
      <guid>https://dev.to/kbytech/removing-identity-from-encryptionconfiguration-before-secrets-are-rewritten-makes-plaintext-secrets-en2</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://www.kbytechnologies.com/config-traps/removing-identity-encryptionconfiguration-before-rewriting-secrets-plaintext-secrets-unreadable" rel="noopener noreferrer"&gt;KBY Technologies&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If your team runs its own Kubernetes control plane and has turned on encryption at rest for Secrets, this is a change a hardening review can ask for. We walk through why removing that one fallback line is only safe after every Secret has been rewritten.&lt;/p&gt;




&lt;p&gt;Encryption at rest for Secrets is switched on, and the hardening guidance says to remove &lt;code&gt;identity: {}&lt;/code&gt; from the provider list so the API server can never read plain text. If that line goes before every existing Secret has been rewritten, the API server stops being able to read any Secret that is still stored in the clear. Put &lt;code&gt;identity: {}&lt;/code&gt; back as the last provider, restart each API server in turn, then rewrite the Secrets and remove it properly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Symptom
&lt;/h2&gt;

&lt;p&gt;The change looks small. A file such as &lt;code&gt;/etc/kubernetes/enc/enc.yaml&lt;/code&gt; loses one line, and the API servers pick it up. Reads of Secrets that were written before encryption was enabled then start to fail, while newer Secrets read normally.&lt;/p&gt;

&lt;p&gt;So the cluster is not down, but it is uneven. Some Secrets read and some do not. Which ones fail depends on when each was last written, not on its namespace or its owner. Anything that needs one of the unreadable Secrets, such as a Pod that references it, has to wait until the Secret can be read again.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why it looks safe to remove the fallback
&lt;/h2&gt;

&lt;p&gt;The Kubernetes documentation for encrypting data at rest lists &lt;code&gt;identity&lt;/code&gt; after the real provider as a fallback that allows reading unencrypted Secrets, for example during the initial migration. Its section on preventing plain text retrieval then says that once all Secrets are encrypted, the line can be removed, which stops the API server accessing a plain-text Secret even by accident.&lt;/p&gt;

&lt;p&gt;The step is sound once the precondition is true. The trap is that nothing in the configuration records the precondition. Turning encryption on only encrypts what is written afterwards, so a cluster can have a working first provider and still hold years of plain-text Secrets. The first-provider check in the documentation does not tell you whether a previous migration to encrypted storage has succeeded.&lt;/p&gt;

&lt;h2&gt;
  
  
  Root cause
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;providers&lt;/code&gt; list is ordered. The first provider encrypts every write. For reads, each provider that matches the stored data tries to decrypt it in order. If no provider can read the stored data, the documentation says an error is returned that prevents clients from accessing that resource.&lt;/p&gt;

&lt;p&gt;Plain-text data is read by &lt;code&gt;identity&lt;/code&gt;. Take that provider away and a Secret still stored in the clear has no provider that can read it. The same page warns that the change prevents the API server retrieving resources that are marked as encrypted at rest but are actually stored in the clear. Existing Secrets are only converted when something replaces them.&lt;/p&gt;

&lt;p&gt;Automatic reload makes it faster. With &lt;code&gt;--encryption-provider-config-automatic-reload=true&lt;/code&gt;, the API server polls the file every minute and applies changes without a restart. A bad edit can therefore land within about a minute, with no restart to mark the moment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Impact
&lt;/h2&gt;

&lt;p&gt;The affected Secrets are unreadable through the API until a provider can read them again. The documentation’s caution about unreadable resources spells out the worst case. If you cannot restore a working configuration, your only recourse is to delete the entry from etcd directly, which discards that Secret.&lt;/p&gt;

&lt;p&gt;A cluster with more than one control plane node adds a second risk. The documentation says the encryption configuration should be identical on every control plane node, because a difference may mean a kube-apiserver cannot decrypt data. Edit one node first and its API server may fail reads that another node still serves.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to confirm it is the missing provider
&lt;/h2&gt;

&lt;p&gt;Three read-only checks settle it. First, find the configuration file the API server uses. On each control plane node, the kube-apiserver static Pod manifest names it with &lt;code&gt;--encryption-provider-config&lt;/code&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo grep -- --encryption-provider-config /etc/kubernetes/manifests/kube-apiserver.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then read that file and look at the provider list for &lt;code&gt;secrets&lt;/code&gt;. If an encrypting provider such as &lt;code&gt;aescbc&lt;/code&gt; is listed and &lt;code&gt;identity&lt;/code&gt; is not, the fallback has gone:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo cat /etc/kubernetes/enc/enc.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Finally, look at what etcd holds for one of the failing Secrets. The documentation reads one Secret out of etcd and pipes it through &lt;code&gt;hexdump -C&lt;/code&gt;. A Secret encrypted by &lt;code&gt;aescbc&lt;/code&gt; starts with the prefix &lt;code&gt;k8s:enc:aescbc:v1:&lt;/code&gt; followed by the key name. A Secret whose content shows as readable text instead is stored in the clear:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ETCDCTL_API=3 etcdctl --endpoints=https://127.0.0.1:2379 --cacert=/etc/kubernetes/pki/etcd/ca.crt --cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.key get /registry/secrets/default/secret1 | hexdump -C
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Replace &lt;code&gt;secret1&lt;/code&gt; and &lt;code&gt;default&lt;/code&gt; with the failing Secret’s name and namespace. Do not paste this output into tickets or chat. For a plain-text Secret it contains the value.&lt;/p&gt;

&lt;h2&gt;
  
  
  The shortcuts that make it worse
&lt;/h2&gt;

&lt;p&gt;Under pressure, two fixes tempt. The first is to put &lt;code&gt;identity: {}&lt;/code&gt; back at the top of the list so the errors stop. That does restore reads, but the first provider encrypts every write. With &lt;code&gt;identity&lt;/code&gt; first, new and updated Secrets are written as plain text, and the documentation says this provider gives no confidentiality protection. The cluster goes back to storing credentials in the clear, and the next audit finds it.&lt;/p&gt;

&lt;p&gt;The second is to delete the unreadable entries from etcd. The documentation names that as the last resort when no working configuration can be restored. It is not a first move. It destroys the Secret, and anything that depended on it needs the value recreated from wherever the credential came from.&lt;/p&gt;

&lt;p&gt;Neither is needed. The fallback only has to be present again, and last. For the surrounding etcd protections that should stay on while you work, see &lt;a href="https://www.kbytechnologies.com/config-traps/etcd-client-port-missing-certificate-authentication-exposes-kubernetes-secrets" rel="noopener noreferrer"&gt;why an etcd client port without certificate authentication exposes every Secret&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Correction
&lt;/h2&gt;

&lt;p&gt;Restore reads first, in an order that never writes plain text. Work on one control plane node at a time, and keep the encrypting provider first throughout. The precondition for the whole procedure is a working copy of the configuration that was in place before the bad edit, and an etcd snapshot.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Back up.&lt;/strong&gt; Copy the encryption configuration file on every control plane node to a root-only directory outside &lt;code&gt;/etc/kubernetes/manifests/&lt;/code&gt;. Take an etcd snapshot with &lt;code&gt;ETCDCTL_API=3 etcdctl --endpoints=https://127.0.0.1:2379 --cacert=/etc/kubernetes/pki/etcd/ca.crt --cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.key snapshot save /var/backups/etcd-before-enc-fix.db&lt;/code&gt;, then check it with &lt;code&gt;etcdutl --write-out=table snapshot status /var/backups/etcd-before-enc-fix.db&lt;/code&gt;. Encrypt the snapshot, because it holds every Secret.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Put the fallback back, as the last provider.&lt;/strong&gt; Under &lt;code&gt;secrets&lt;/code&gt;, list the encrypting provider first and add &lt;code&gt;- identity: {}&lt;/code&gt; after it, as in the documentation’s configuration. Keep the keys exactly as they were. Precondition: the file is identical on every control plane node when you finish. Rollback: restore the backed-up file.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Restart each kube-apiserver in turn.&lt;/strong&gt; Do one node, confirm that the Secret now reads (&lt;code&gt;kubectl get secret secret1 -n default -o yaml&lt;/code&gt;), then move to the next. If automatic reload is on, wait for the poll interval instead.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Rewrite every Secret.&lt;/strong&gt; As an administrator who can read and write all Secrets, run &lt;code&gt;kubectl get secrets --all-namespaces -o json | kubectl replace -f -&lt;/code&gt;. The documentation says to retry on a conflicting write and that it is safe to run more than once. On a large cluster, run it per namespace. Rollback: none is needed, because the command writes the same data with the first provider.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Check, then remove the fallback.&lt;/strong&gt; Only when the spot checks below pass, remove &lt;code&gt;identity: {}&lt;/code&gt;, and apply the change to each API server in turn, exactly as for step 3.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Verification
&lt;/h2&gt;

&lt;p&gt;After step 4, read several Secrets from etcd with the &lt;code&gt;hexdump&lt;/code&gt; check, taking some of the oldest in different namespaces. Each should start with &lt;code&gt;k8s:enc:aescbc:v1:&lt;/code&gt; and the key name from the file. The documentation gives this check one Secret at a time, so sample widely rather than assuming the cluster is done.&lt;/p&gt;

&lt;p&gt;Then run &lt;code&gt;kubectl get secret secret1 -n default -o yaml&lt;/code&gt; and confirm the data is returned as before. After the fallback is removed, repeat the reads through the API for the same Secrets. Any that fail mean the rewrite missed them, so restore the fallback and run step 4 again.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rollback
&lt;/h2&gt;

&lt;p&gt;Every change here is a file edit that can be reversed. Restore the backed-up encryption configuration on each node, then restart the API servers one at a time so every node is the same. The Secret rewrite needs no undoing.&lt;/p&gt;

&lt;p&gt;The etcd snapshot is for damaged data only. Restoring it rewinds the whole cluster to the moment it was taken, so it is not a way to undo a configuration edit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Stop it happening next time
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Treat &lt;code&gt;identity&lt;/code&gt; removal as the last step of a migration, never part of enabling encryption. Make the ticket require the rewrite to be run and sampled first.&lt;/li&gt;
&lt;li&gt;Change one control plane node at a time and compare the file on every node afterwards, as the documentation requires identical configurations.&lt;/li&gt;
&lt;li&gt;If automatic reload is enabled, remember that a saved edit applies within about a minute. Make the change on a copy, check it, then move it into place.&lt;/li&gt;
&lt;li&gt;Rotating keys has its own order, and the documentation covers it: add the new key second, restart, make it first, restart, rewrite the Secrets, then remove the old key. A related renewal trap is described in &lt;a href="https://www.kbytechnologies.com/config-traps/kubeadm-certs-renew-without-static-pod-restart-etcd-api-server-expiring-certificates" rel="noopener noreferrer"&gt;kubeadm certs renew without a static Pod restart&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Originally published at KBY Technologies: &lt;a href="https://www.kbytechnologies.com/config-traps/removing-identity-encryptionconfiguration-before-rewriting-secrets-plaintext-secrets-unreadable?utm_source=devto&amp;amp;utm_medium=syndication" rel="noopener noreferrer"&gt;Removing identity From EncryptionConfiguration Before Secrets Are Rewritten Makes Plaintext Secrets Unreadable&lt;/a&gt;&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>security</category>
      <category>devops</category>
      <category>sysadmin</category>
    </item>
    <item>
      <title>Deleting a SharePoint Data Source From a Bedrock Knowledge Base Set to RETAIN Leaves Its Text in the Vector Store</title>
      <dc:creator>KBY Technologies</dc:creator>
      <pubDate>Sun, 22 Nov 2026 13:59:06 +0000</pubDate>
      <link>https://dev.to/kbytech/deleting-a-sharepoint-data-source-from-a-bedrock-knowledge-base-set-to-retain-leaves-its-text-in-o79</link>
      <guid>https://dev.to/kbytech/deleting-a-sharepoint-data-source-from-a-bedrock-knowledge-base-set-to-retain-leaves-its-text-in-o79</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://www.kbytechnologies.com/config-traps/bedrock-knowledge-base-sharepoint-data-source-retain-leaves-text-in-vector-store" rel="noopener noreferrer"&gt;KBY Technologies&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If your team builds retrieval assistants on Amazon Bedrock knowledge bases and indexes SharePoint sites, this is the clean-up step that gets skipped when a source is retired. We cover how to read the deletion policy first and the order of changes that actually removes the synced text.&lt;/p&gt;




&lt;h2&gt;
  
  
  Symptom
&lt;/h2&gt;

&lt;p&gt;Deleting a SharePoint Online data source from an Amazon Bedrock knowledge base removes the connector, but if its data deletion policy is &lt;code&gt;RETAIN&lt;/code&gt;, every chunk of SharePoint text it synced stays in the vector store. The console shows a green banner, the source disappears from the list, and the site looks disconnected. The embeddings and the raw text Bedrock wrote alongside them are still in the vector index. Deleting the whole knowledge base doesn’t remove them either. The fix is an order of operations: read the policy, change it to &lt;code&gt;DELETE&lt;/code&gt; with &lt;code&gt;update-data-source&lt;/code&gt;, confirm it, and only then delete the data source and watch for &lt;code&gt;DELETE_UNSUCCESSFUL&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;A typical case: a team stops indexing an HR or legal SharePoint site because its content should no longer be searchable through an assistant. The data source goes, the ticket closes, and the text stays in a store that SharePoint permissions never governed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why removing the data source looks safe
&lt;/h2&gt;

&lt;p&gt;Deleting the data source feels like the end of the connection. The SharePoint site is untouched, the Entra ID app can be retired afterwards, and the knowledge base no longer lists the source. The deletion policy is set once, when the data source is created or modified, and nobody looks at it again when it is removed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Root cause
&lt;/h2&gt;

&lt;p&gt;The data deletion policy, not the delete action, decides what happens to synced content. The Amazon Bedrock API reference defines two values for &lt;code&gt;dataDeletionPolicy&lt;/code&gt;. &lt;code&gt;DELETE&lt;/code&gt; deletes all data from the data source that has been converted into vector embeddings when the data source or knowledge base is deleted. &lt;code&gt;RETAIN&lt;/code&gt; keeps all of that data in the same situation. With either value, the vector store itself is never deleted.&lt;/p&gt;

&lt;p&gt;What stays is more than numbers. When you set up a vector store for a knowledge base, you map a text field that AWS describes as the field in which to store the raw text from your data sources, next to the vector field and a metadata field Bedrock manages. So a retained SharePoint source leaves readable passages of its documents behind, not only embeddings.&lt;/p&gt;

&lt;p&gt;This applies to knowledge bases backed by a vector store you supply. For an Amazon Bedrock managed knowledge base, AWS documents &lt;code&gt;DELETE&lt;/code&gt; as the only supported option and the default.&lt;/p&gt;

&lt;h2&gt;
  
  
  Impact
&lt;/h2&gt;

&lt;p&gt;The retained text sits outside SharePoint’s permissions and outside the knowledge base’s lifecycle. The SharePoint connector page warns that all data synced from the source becomes available to anyone with &lt;code&gt;bedrock:Retrieve&lt;/code&gt; permission on the knowledge base, including data that had controlled permissions in the source. Removing the source is how most teams try to take that exposure away. With &lt;code&gt;RETAIN&lt;/code&gt;, the text is still readable by anyone who can read the vector index, and it stays there after the SharePoint documents are deleted or restricted. It is the same pattern as &lt;a href="https://www.kbytechnologies.com/config-traps/s3-default-bucket-encryption-skips-existing-objects" rel="noopener noreferrer"&gt;S3 default encryption, which never touches objects uploaded before it was enabled&lt;/a&gt;: the setting you rely on doesn’t act on data that already exists.&lt;/p&gt;

&lt;h2&gt;
  
  
  Shortcuts that make it worse
&lt;/h2&gt;

&lt;p&gt;Deleting the whole knowledge base looks thorough. It isn’t: &lt;code&gt;RETAIN&lt;/code&gt; covers deletion of the knowledge base as well as the data source, and the vector store is not deleted. You lose the configuration of every other source and the SharePoint text remains.&lt;/p&gt;

&lt;p&gt;Deleting the vector index or collection by hand does remove the text, along with the embeddings of every other data source stored in it. That is a destructive change outside Bedrock, and the only way back is to rebuild the index and sync every source again.&lt;/p&gt;

&lt;p&gt;Revoking the Entra ID app’s &lt;code&gt;Sites.Read.All&lt;/code&gt; consent, or deleting its client secret, stops future syncs. Nothing in that change touches what is already in the index. Leave it until last, because you need those credentials if you have to recreate and re-sync the source.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to confirm the policy before you delete
&lt;/h2&gt;

&lt;p&gt;Two read-only AWS CLI calls show which sources are affected. List the data sources in the knowledge base:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws bedrock-agent list-data-sources --knowledge-base-id KB12345678 --query "dataSourceSummaries[].[dataSourceId,name,status]"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then read the policy and status of the SharePoint source:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws bedrock-agent get-data-source --knowledge-base-id KB12345678 --data-source-id DS12345678 --query "dataSource.[name,dataDeletionPolicy,status]"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If the second value is &lt;code&gt;RETAIN&lt;/code&gt;, deleting this source now leaves its text in the vector store. If the source is already gone and was set to &lt;code&gt;RETAIN&lt;/code&gt;, Bedrock’s data source calls can no longer reach that text. Deleting the knowledge base won’t remove it either. The clean-up becomes a separate, reviewed change in the vector store, made by whoever owns that store.&lt;/p&gt;

&lt;h2&gt;
  
  
  Correction
&lt;/h2&gt;

&lt;p&gt;Change the policy on the live data source first, confirm it, and delete only after that. Before you start, check that SharePoint is still the system of record for every document the source indexes, so that a re-sync can rebuild anything removed by mistake, and that you hold &lt;code&gt;bedrock:GetDataSource&lt;/code&gt; and &lt;code&gt;bedrock:UpdateDataSource&lt;/code&gt;. AWS’s knowledge base permissions page says to treat data source actions as privileged, so make this change through your normal change process.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Back up the full data source definition, then extract the two parts the update needs:&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws bedrock-agent get-data-source --knowledge-base-id KB12345678 --data-source-id DS12345678 --query "dataSource" --output json &amp;gt; ds-backup.json
aws bedrock-agent get-data-source --knowledge-base-id KB12345678 --data-source-id DS12345678 --query "dataSource.dataSourceConfiguration" --output json &amp;gt; ds-config.json
aws bedrock-agent get-data-source --knowledge-base-id KB12345678 --data-source-id DS12345678 --query "dataSource.vectorIngestionConfiguration" --output json &amp;gt; ds-vector.json
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;UpdateDataSource&lt;/code&gt; requires the name and the data source configuration, and the chunking configuration can’t be changed after creation, so pass the existing one back unchanged. If &lt;code&gt;ds-vector.json&lt;/code&gt; contains only &lt;code&gt;null&lt;/code&gt;, leave the &lt;code&gt;--vector-ingestion-configuration&lt;/code&gt; option out. If &lt;code&gt;ds-backup.json&lt;/code&gt; shows a &lt;code&gt;description&lt;/code&gt; or a &lt;code&gt;serverSideEncryptionConfiguration&lt;/code&gt;, pass those back as well with &lt;code&gt;--description&lt;/code&gt; and &lt;code&gt;--server-side-encryption-configuration&lt;/code&gt;, so the update changes nothing but the policy.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Switch the policy, keeping everything else as it was. Use the name the earlier check returned:&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws bedrock-agent update-data-source --knowledge-base-id KB12345678 --data-source-id DS12345678 --name hr-sharepoint --data-source-configuration file://ds-config.json --vector-ingestion-configuration file://ds-vector.json --data-deletion-policy DELETE
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Stop if the call returns an error. Nothing has been deleted at this point.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run the &lt;code&gt;get-data-source&lt;/code&gt; check again and confirm it now reports &lt;code&gt;DELETE&lt;/code&gt; and &lt;code&gt;AVAILABLE&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Delete the data source. In the console, choose Knowledge bases in the left navigation pane, open the knowledge base, select the source in the Data source section and choose Delete, or send a &lt;code&gt;DeleteDataSource&lt;/code&gt; request. This removes the synced data from the vector store and can’t be undone; the recovery path is to recreate the source and sync it again.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Only after the source has gone, and after checking with &lt;code&gt;get-data-source&lt;/code&gt; that no other data source names the same &lt;code&gt;credentialsSecretArn&lt;/code&gt;, retire the Entra ID client secret and the AWS Secrets Manager secret that held it. AWS advises against reusing credentials across data sources, but check rather than assume.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Validation
&lt;/h2&gt;

&lt;p&gt;A successful deletion ends with the source missing from &lt;code&gt;list-data-sources&lt;/code&gt;, not stuck in a failed state. Run the list command again. A source still shown as &lt;code&gt;DELETING&lt;/code&gt; is in progress. A source shown as &lt;code&gt;DELETE_UNSUCCESSFUL&lt;/code&gt; means Bedrock couldn’t remove the data, which AWS says can happen because of problems with the configuration of, or access to, the vector store. Read the reason:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws bedrock-agent get-data-source --knowledge-base-id KB12345678 --data-source-id DS12345678 --query "dataSource.failureReasons"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Fix the access problem it names and delete again. Then have the owner of the vector store confirm that no records from the SharePoint site remain in the index.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rollback
&lt;/h2&gt;

&lt;p&gt;Each step before the deletion can be reversed with the files you saved. To undo the policy change, run the same &lt;code&gt;update-data-source&lt;/code&gt; command with &lt;code&gt;--data-deletion-policy RETAIN&lt;/code&gt;. After the deletion there is nothing to roll back in place: create a new SharePoint data source from the configuration in &lt;code&gt;ds-backup.json&lt;/code&gt; and sync it, which rebuilds the index from SharePoint. That only works while the Entra ID app and its secret still exist, which is why they go last.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prevent it on the next SharePoint source
&lt;/h2&gt;

&lt;p&gt;Set &lt;code&gt;dataDeletionPolicy&lt;/code&gt; explicitly when you create every data source, rather than relying on whatever the tool you use fills in, and record the value in the change that creates it. Add the &lt;code&gt;get-data-source&lt;/code&gt; check to the steps for decommissioning a source, so the policy is read before anyone presses Delete. Keep data source permissions with the few people who own the knowledge base. For a related case of a clean-up deleting the wrong thing because the order was wrong, see &lt;a href="https://www.kbytechnologies.com/config-traps/ecr-lifecycle-untagged-images-expire-ecs-service-digest" rel="noopener noreferrer"&gt;how expiring untagged ECR images removes a digest an ECS service still runs&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;Read the original on KBY Technologies: &lt;a href="https://www.kbytechnologies.com/config-traps/bedrock-knowledge-base-sharepoint-data-source-retain-leaves-text-in-vector-store?utm_source=devto&amp;amp;utm_medium=syndication" rel="noopener noreferrer"&gt;Deleting a SharePoint Data Source From a Bedrock Knowledge Base Set to RETAIN Leaves Its Text in the Vector Store&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>security</category>
      <category>devops</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Adding a Broker Role in Front of a Deployment Role Caps Its Sessions at One Hour, Whatever MaxSessionDuration Says</title>
      <dc:creator>KBY Technologies</dc:creator>
      <pubDate>Sat, 21 Nov 2026 16:14:24 +0000</pubDate>
      <link>https://dev.to/kbytech/adding-a-broker-role-in-front-of-a-deployment-role-caps-its-sessions-at-one-hour-whatever-2mn4</link>
      <guid>https://dev.to/kbytech/adding-a-broker-role-in-front-of-a-deployment-role-caps-its-sessions-at-one-hour-whatever-2mn4</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://www.kbytechnologies.com/config-traps/broker-role-iam-role-chaining-caps-session-one-hour" rel="noopener noreferrer"&gt;KBY Technologies&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If your pipeline assumes AWS roles from CI and someone on the team wants a broker role in front of the deployment role, this is the change that quietly caps its sessions at one hour. We cover why the second hop is capped, the read-only commands that show it, and how to give the pipeline a single hop instead.&lt;/p&gt;




&lt;h2&gt;
  
  
  Symptom
&lt;/h2&gt;

&lt;p&gt;A deployment pipeline that ran for hours under one IAM role starts failing after someone puts a broker role in front of it. Before the change, the pipeline signed in through its OIDC provider straight into &lt;code&gt;DeployRole&lt;/code&gt;, which has a maximum session duration of four hours, and asked for three. After the change, it signs in to &lt;code&gt;ci-broker&lt;/code&gt; first and assumes &lt;code&gt;DeployRole&lt;/code&gt; from there. Now the &lt;code&gt;AssumeRole&lt;/code&gt; call fails as soon as it asks for more than 3,600 seconds, or, if the duration is removed, long jobs lose their credentials an hour in. Raising &lt;code&gt;DeployRole&lt;/code&gt;‘s maximum session duration changes nothing. The second hop is role chaining, and AWS limits a chained role session to one hour whatever the role’s own setting says. The fix is to give the pipeline a single hop into the role it needs, not to raise limits or switch to access keys.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why a broker role looks safe
&lt;/h2&gt;

&lt;p&gt;A broker role keeps one trust relationship with the CI provider and hands out narrower roles behind it. The deployment role’s permissions don’t change, its trust policy only gains the broker as a principal, and a short test run succeeds. Nothing in the change mentions session length, and the role’s &lt;code&gt;MaxSessionDuration&lt;/code&gt; still reads 14,400 seconds in &lt;code&gt;get-role&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Root cause
&lt;/h2&gt;

&lt;p&gt;Credentials from one role were used to assume another, and AWS caps that second session at one hour. The IAM User Guide calls this role chaining and says it limits an AWS Management Console, AWS CLI or API role session to a maximum of one hour, regardless of the maximum session duration configured for the individual roles. The &lt;code&gt;AssumeRole&lt;/code&gt; reference adds the consequence: if you assume a role through role chaining and pass a &lt;code&gt;DurationSeconds&lt;/code&gt; value greater than one hour, the operation fails.&lt;/p&gt;

&lt;p&gt;The first hop isn’t affected. A session from &lt;code&gt;AssumeRoleWithWebIdentity&lt;/code&gt; can last from 900 seconds up to the role’s maximum session duration, and that setting can be anything from one to twelve hours. AWS also documents that the one-hour limit doesn’t apply to the initial assumption of a role from user credentials, or to applications on Amazon EC2 instances using instance profiles. So the same deployment role gives a three-hour session when it is the first hop and a one-hour session when it is the second.&lt;/p&gt;

&lt;h2&gt;
  
  
  Impact
&lt;/h2&gt;

&lt;p&gt;Any job behind the broker that runs longer than an hour fails partway through. That means long infrastructure deployments, large copies and database migrations, which can stop half-applied and need someone to finish or roll them back by hand. Jobs that explicitly request more than an hour fail before they start, which is at least obvious. Jobs that request no duration get the one-hour default, pass every short test, and fail only on the long runs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Workarounds that cost more than they fix
&lt;/h2&gt;

&lt;p&gt;Raising &lt;code&gt;MaxSessionDuration&lt;/code&gt; on &lt;code&gt;DeployRole&lt;/code&gt; to twelve hours does nothing for the chained session, because the limit applies regardless of that setting. It does leave every future direct session of that role able to run for twelve hours, which nobody asked for.&lt;/p&gt;

&lt;p&gt;Giving the pipeline an IAM user with access keys works, because the limit doesn’t apply when a role is first assumed from user credentials. It also puts long-term credentials back into a CI system. AWS’s IAM best practices say workloads, including managed CI/CD platforms, should use temporary credentials through IAM roles, and keys you create then need rotating and watching, as the trap of &lt;a href="https://www.kbytechnologies.com/config-traps/iam-console-password-reset-leaves-access-keys-active" rel="noopener noreferrer"&gt;a console password reset that leaves access keys active&lt;/a&gt; shows.&lt;/p&gt;

&lt;p&gt;Granting the broker role the deployment permissions directly removes the second hop, but it turns the broker into the most privileged role in the chain, which is the opposite of what it was added for. AWS’s best practices list least-privilege permissions for this reason.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to confirm it is role chaining
&lt;/h2&gt;

&lt;p&gt;These checks read configuration or issue short-lived credentials; none of them changes a role. Use your own role names and account ID.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Read the deployment role’s maximum session duration and who it trusts.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws iam get-role --role-name DeployRole \
  --query &lt;span class="s2"&gt;"Role.[MaxSessionDuration,AssumeRolePolicyDocument]"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;A value of 14400 alongside a trust policy that names &lt;code&gt;ci-broker&lt;/code&gt; as a principal is the shape of this trap.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In the pipeline, just before it assumes &lt;code&gt;DeployRole&lt;/code&gt;, print the identity it is calling from.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws sts get-caller-identity
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;If &lt;code&gt;Arn&lt;/code&gt; is an assumed-role ARN for &lt;code&gt;ci-broker&lt;/code&gt; rather than an IAM user, the next &lt;code&gt;AssumeRole&lt;/code&gt; call is role chaining.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;From the same place, request one hour, then two.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws sts assume-role --role-arn arn:aws:iam::111122223333:role/DeployRole \
  --role-session-name chain-check --duration-seconds 3600 \
  --query &lt;span class="s2"&gt;"Credentials.Expiration"&lt;/span&gt;
aws sts assume-role --role-arn arn:aws:iam::111122223333:role/DeployRole \
  --role-session-name chain-check --duration-seconds 7200 \
  --query &lt;span class="s2"&gt;"Credentials.Expiration"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;The first returns an expiry an hour away; the second fails, even though 7,200 seconds is well inside the role’s 14,400. Discard the credentials and don’t paste them anywhere.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Correction
&lt;/h2&gt;

&lt;p&gt;Give the pipeline one hop into &lt;code&gt;DeployRole&lt;/code&gt; by trusting the OIDC provider directly, adding the new path before removing the old one. You need permission to read and update the role’s trust policy, and the trust statement the broker role uses for your CI provider: its &lt;code&gt;Federated&lt;/code&gt; principal, the &lt;code&gt;sts:AssumeRoleWithWebIdentity&lt;/code&gt; action and its conditions.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Save the current trust policy so you can put it back exactly.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws iam get-role --role-name DeployRole \
  --query &lt;span class="s2"&gt;"Role.AssumeRolePolicyDocument"&lt;/span&gt; --output json &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; deployrole-trust-before.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Write &lt;code&gt;deployrole-trust-after.json&lt;/code&gt;: the saved document plus one statement copied from &lt;code&gt;ci-broker&lt;/code&gt;‘s trust policy, with the same provider and the same conditions. Leave the existing &lt;code&gt;ci-broker&lt;/code&gt; statement in place for now. Don’t loosen the conditions while copying them; a wider condition would let more callers into the deployment role.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Apply it.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws iam update-assume-role-policy --role-name DeployRole \
  --policy-document file://deployrole-trust-after.json
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;If &lt;code&gt;get-role&lt;/code&gt; doesn’t show both statements afterwards, or anything that assumed the role before now fails, restore the saved file the same way and stop.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Change one pipeline to assume &lt;code&gt;DeployRole&lt;/code&gt; directly with web identity, requesting no more than the role’s &lt;code&gt;MaxSessionDuration&lt;/code&gt;, and run its longest job. Move the other pipelines once it completes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When nothing has used the &lt;code&gt;ci-broker&lt;/code&gt; path into &lt;code&gt;DeployRole&lt;/code&gt; for a full release cycle, remove that statement with another &lt;code&gt;update-assume-role-policy&lt;/code&gt;, saving the document first as in step 1.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If the broker has to stay, for example because it adds checks you rely on, the other honest option is to keep chained sessions under an hour and split long jobs so each stage gets fresh credentials. The AWS CLI documents that a role profile reuses cached temporary credentials until they expire and then refreshes them automatically, which helps a job made of many short commands but not one long call.&lt;/p&gt;

&lt;h2&gt;
  
  
  Validation
&lt;/h2&gt;

&lt;p&gt;The fix holds when the pipeline’s longest job completes on a single hop and the role trusts nobody new.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;aws sts get-caller-identity&lt;/code&gt; inside the job shows an assumed-role ARN for &lt;code&gt;DeployRole&lt;/code&gt;, reached without first becoming &lt;code&gt;ci-broker&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The credentials’ &lt;code&gt;Expiration&lt;/code&gt; is as far away as the duration the pipeline requested, beyond one hour.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;aws iam get-role --role-name DeployRole&lt;/code&gt; shows the copied OIDC statement with the same conditions as the broker’s, and no wider ones.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Rollback
&lt;/h2&gt;

&lt;p&gt;Every step is reversed by putting back a saved trust policy.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Trust policy: &lt;code&gt;aws iam update-assume-role-policy --role-name DeployRole --policy-document file://deployrole-trust-before.json&lt;/code&gt; restores the policy exactly as it was.&lt;/li&gt;
&lt;li&gt;Pipeline: point it back at &lt;code&gt;ci-broker&lt;/code&gt; and request no more than 3,600 seconds for the chained session.&lt;/li&gt;
&lt;li&gt;If you changed &lt;code&gt;MaxSessionDuration&lt;/code&gt; while troubleshooting, set it back with &lt;code&gt;aws iam update-role --role-name DeployRole --max-session-duration 14400&lt;/code&gt;. AWS notes the new value applies the next time someone assumes the role.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Prevent it on the next role change
&lt;/h2&gt;

&lt;p&gt;Before you put any role in front of another, list the jobs behind it that run longer than an hour, because the chained session can’t outlast that whatever either role says. Check how long the longest stage really runs, not how long it usually runs. Note which roles are reached by chaining in the role’s description, so the next person who reads &lt;code&gt;MaxSessionDuration&lt;/code&gt; knows it doesn’t apply on that path. Chaining has other sharp edges too; &lt;a href="https://www.kbytechnologies.com/config-traps/iam-role-chaining-through-lambda-passrole-wildcards" rel="noopener noreferrer"&gt;role chaining through Lambda PassRole wildcards&lt;/a&gt; covers the permissions side.&lt;/p&gt;




&lt;p&gt;Read the original on KBY Technologies: &lt;a href="https://www.kbytechnologies.com/config-traps/broker-role-iam-role-chaining-caps-session-one-hour?utm_source=devto&amp;amp;utm_medium=syndication" rel="noopener noreferrer"&gt;Adding a Broker Role in Front of a Deployment Role Caps Its Sessions at One Hour, Whatever MaxSessionDuration Says&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>devops</category>
      <category>security</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Adding a Second User-Assigned Managed Identity to an Azure VM Breaks Apps That Never Named Their Identity</title>
      <dc:creator>KBY Technologies</dc:creator>
      <pubDate>Fri, 20 Nov 2026 15:45:59 +0000</pubDate>
      <link>https://dev.to/kbytech/adding-a-second-user-assigned-managed-identity-to-an-azure-vm-breaks-apps-that-never-named-their-306d</link>
      <guid>https://dev.to/kbytech/adding-a-second-user-assigned-managed-identity-to-an-azure-vm-breaks-apps-that-never-named-their-306d</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://www.kbytechnologies.com/config-traps/azure-vm-second-user-assigned-managed-identity-breaks-token-requests" rel="noopener noreferrer"&gt;KBY Technologies&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you ship code to Azure virtual machines that fetch tokens from the Instance Metadata Service, this is a trap that hits you the day someone else attaches a second user-assigned managed identity to the same VM. We cover which of your apps and scripts are exposed, the read-only commands that show it, and how to fix it without adding a system-assigned identity or a client secret.&lt;/p&gt;




&lt;h2&gt;
  
  
  Symptom
&lt;/h2&gt;

&lt;p&gt;An application on an Azure virtual machine that has read from Key Vault or Storage for months stops getting tokens. The change that day was routine: someone attached a second user-assigned managed identity to the VM so another workload could use it. The first identity and its role assignments are untouched. The application never said which identity it wanted, and with one user-assigned identity it didn’t have to. With two, the Instance Metadata Service (IMDS) has to be told which one to use, so the token request fails. Fix the application first by giving it the client ID of the identity that holds its roles. Don’t turn on the system-assigned identity, and don’t go back to a client secret.&lt;/p&gt;

&lt;p&gt;This applies to a VM with no system-assigned identity that went from one user-assigned identity to two or more. A VM that already has a system-assigned identity behaves differently, as covered below.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why attaching an identity looks safe
&lt;/h2&gt;

&lt;p&gt;Microsoft supports this setup. A resource can have a system-assigned identity and one or more user-assigned identities, and Microsoft’s best-practice guidance describes sharing one user-assigned identity across many resources so fewer role assignments are needed. Assigning an identity to a VM changes no role assignments and detaches nothing, so in a change review it reads as additive and low risk. The person making the change usually owns the new workload, not the application that breaks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Root cause
&lt;/h2&gt;

&lt;p&gt;The application’s token request names no identity, and Microsoft documents that a VM with more than one user-assigned identity needs one named. Code on the VM gets a managed identity token from the IMDS endpoint &lt;code&gt;http://169.254.169.254/metadata/identity/oauth2/token&lt;/code&gt;. Microsoft documents three optional query parameters that pick the identity: &lt;code&gt;client_id&lt;/code&gt;, &lt;code&gt;object_id&lt;/code&gt; and &lt;code&gt;msi_res_id&lt;/code&gt;. Each is marked as required if the VM has multiple user-assigned managed identities. A request that names none of them worked while there was only one identity to choose. Attach a second, and the same request no longer says which identity to use.&lt;/p&gt;

&lt;p&gt;The Azure Identity libraries pass whatever identity they were configured with. In Python, &lt;code&gt;DefaultAzureCredential&lt;/code&gt; takes &lt;code&gt;managed_identity_client_id&lt;/code&gt;, which defaults to the &lt;code&gt;AZURE_CLIENT_ID&lt;/code&gt; environment variable; if neither is set, it uses a system-assigned identity. In .NET, &lt;code&gt;AZURE_CLIENT_ID&lt;/code&gt;, if defined, is the default for &lt;code&gt;ManagedIdentityClientId&lt;/code&gt;. An application with neither configured sends no identity at all.&lt;/p&gt;

&lt;p&gt;IMDS reports request errors with a 4xx status and a JSON body with &lt;code&gt;error&lt;/code&gt; and &lt;code&gt;error_description&lt;/code&gt;. Its documentation calls 4xx errors design-time errors and says not to retry them, so retry logic will not get the application working again.&lt;/p&gt;

&lt;h2&gt;
  
  
  Impact
&lt;/h2&gt;

&lt;p&gt;Every process on the VM that asks for a token without naming an identity fails the next time it needs a new token: the application, scheduled scripts that call IMDS with &lt;code&gt;curl&lt;/code&gt; or &lt;code&gt;Invoke-RestMethod&lt;/code&gt;, and any agent built the same way. The new workload usually works, because whoever set it up named its identity, so the change looks fine to the person who made it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three tempting fixes that make it worse
&lt;/h2&gt;

&lt;p&gt;The first is to turn on the VM’s system-assigned identity. The Python library documents that, with no client ID, it uses a system-assigned identity, so token requests succeed again. But the token now belongs to a new identity with none of the application’s roles, so the failure moves to the Key Vault or Storage call. The next step under pressure is to grant that identity the same roles. Two identities then hold the same access, and Microsoft notes that role assignments are not deleted automatically when an identity is deleted.&lt;/p&gt;

&lt;p&gt;The second is to fall back to a service principal secret in &lt;code&gt;AZURE_CLIENT_ID&lt;/code&gt;, &lt;code&gt;AZURE_TENANT_ID&lt;/code&gt; and &lt;code&gt;AZURE_CLIENT_SECRET&lt;/code&gt;. &lt;code&gt;DefaultAzureCredential&lt;/code&gt; tries a service principal from environment variables before managed identity, so this works. It also brings back the secret that managed identities exist to remove, and you now have to store and rotate it. The same trade appears when a storage client goes back to account keys, covered in &lt;a href="https://www.kbytechnologies.com/runbooks/azure-storage-security-identity/azure-storage-403-shared-key-access-disabled" rel="noopener noreferrer"&gt;fixing Storage 403 errors after Shared Key access is disabled&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The third is to remove the new identity. That restores the old behaviour and breaks the workload it was added for, and the next person to attach an identity will hit the same failure.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to confirm the diagnosis
&lt;/h2&gt;

&lt;p&gt;These checks change nothing. Replace &lt;code&gt;rg-app&lt;/code&gt;, &lt;code&gt;app01&lt;/code&gt; and the IDs with your own.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;List the VM’s identities. You are looking for a type with no &lt;code&gt;SystemAssigned&lt;/code&gt; and two or more entries under &lt;code&gt;userAssignedIdentities&lt;/code&gt;.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   az vm identity show --name app01 --resource-group rg-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Get each identity’s client ID and principal ID from its resource ID.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   az identity show --ids &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;identity-resource-id&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; \
     --query &lt;span class="s2"&gt;"{clientId:clientId, principalId:principalId}"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Find the identity that holds the application’s roles. Without &lt;code&gt;--all&lt;/code&gt;, only subscription-scope assignments are listed.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   az role assignment list --assignee &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;principal-id&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; --all --output table
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;On the VM, request a token twice: once as the application does, and once with that identity’s client ID. If the first fails and the second returns an &lt;code&gt;access_token&lt;/code&gt;, the diagnosis is confirmed. Don’t paste the token into a ticket.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   curl -s -H Metadata:true \
     &lt;span class="s1"&gt;'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&amp;amp;resource=https%3A%2F%2Fmanagement.azure.com%2F'&lt;/span&gt;
   curl -s -H Metadata:true \
     &lt;span class="s1"&gt;'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&amp;amp;resource=https%3A%2F%2Fmanagement.azure.com%2F&amp;amp;client_id=&amp;lt;client-id&amp;gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Correction
&lt;/h2&gt;

&lt;p&gt;Name the identity in the application before you change anything on the VM. That way the VM never has an identity layout the application can’t use. You need access to the application’s configuration. For the identity changes, you also need Virtual Machine Contributor, plus Managed Identity Operator to assign a user-assigned identity.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Save the current state: &lt;code&gt;az vm identity show --name app01 --resource-group rg-app &amp;gt; vm-identity-before.json&lt;/code&gt;, and a copy of the application’s configuration or service definition.&lt;/li&gt;
&lt;li&gt;Pin the application to the identity that holds its roles. Set &lt;code&gt;AZURE_CLIENT_ID&lt;/code&gt; to that identity’s client ID in the application’s environment, or pass it in code as &lt;code&gt;managed_identity_client_id&lt;/code&gt; (Python) or &lt;code&gt;ManagedIdentityClientId&lt;/code&gt; (.NET). Don’t add &lt;code&gt;AZURE_TENANT_ID&lt;/code&gt; or &lt;code&gt;AZURE_CLIENT_SECRET&lt;/code&gt;. Restart the application. If token errors continue, check that the client ID matches an identity listed by &lt;code&gt;az vm identity show&lt;/code&gt; before you try anything else.&lt;/li&gt;
&lt;li&gt;Do the same for every other process on the VM that requests tokens. Scripts that call IMDS directly need &lt;code&gt;client_id=&lt;/code&gt; in the query string.&lt;/li&gt;
&lt;li&gt;If you removed the second identity to get running again, assign it back only after steps 2 and 3:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   az vm identity assign -g rg-app -n app01 --identities &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;identity-resource-id&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If anything on the VM starts failing to get a token, remove it again with &lt;code&gt;az vm identity remove -g rg-app -n app01 --identities &amp;lt;identity-name&amp;gt;&lt;/code&gt; and find the process that still sends no identity.&lt;/p&gt;

&lt;h2&gt;
  
  
  Validation
&lt;/h2&gt;

&lt;p&gt;The fix holds when every workload on the VM gets a token for its own identity and nothing extra was granted along the way.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The application reads from Key Vault or Storage again, with no token errors in its log.&lt;/li&gt;
&lt;li&gt;The IMDS request with &lt;code&gt;client_id&lt;/code&gt; returns a token, and &lt;code&gt;az vm identity show&lt;/code&gt; still lists every identity the VM’s workloads need.&lt;/li&gt;
&lt;li&gt;No system-assigned identity or client secret was added on the way. If &lt;code&gt;az role assignment list&lt;/code&gt; on an identity added during the incident shows copies of the application’s roles, remove them once the pinned application has run cleanly, so only one identity holds that access.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the pinned request gets a token but the resource still answers 403, the problem is authorisation, not identity selection. The &lt;a href="https://www.kbytechnologies.com/config-traps/key-vault-forbidden-owner-role-rbac-vault" rel="noopener noreferrer"&gt;Owner role on an RBAC Key Vault returning Forbidden&lt;/a&gt; is one case to check next.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rollback
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Application setting: remove &lt;code&gt;AZURE_CLIENT_ID&lt;/code&gt; or the code option and restart. This is only safe while the VM has a single user-assigned identity.&lt;/li&gt;
&lt;li&gt;Identity assignment: &lt;code&gt;az vm identity remove -g rg-app -n app01 --identities &amp;lt;identity-name&amp;gt;&lt;/code&gt; removes an identity you added, and &lt;code&gt;az vm identity assign&lt;/code&gt; puts back one you removed, using the IDs saved in &lt;code&gt;vm-identity-before.json&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Stop it happening on the next change
&lt;/h2&gt;

&lt;p&gt;Configure the client ID in every application that uses a user-assigned identity, even when the VM has only one. The setting changes nothing today, and it means the next identity anyone attaches can’t break the application. Before you approve a change that attaches an identity to a VM, ask the owners of everything already running there whether their code names its identity. The two token requests above show it without changing anything.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Read the original, with the rest of the Config Traps library, on &lt;a href="https://www.kbytechnologies.com/config-traps/azure-vm-second-user-assigned-managed-identity-breaks-token-requests?utm_source=devto&amp;amp;utm_medium=syndication" rel="noopener noreferrer"&gt;KBY Technologies&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>azure</category>
      <category>devops</category>
      <category>security</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Expiring Untagged ECR Images Deletes the Digest an ECS Service Still Runs, and New Tasks Fail to Pull</title>
      <dc:creator>KBY Technologies</dc:creator>
      <pubDate>Thu, 19 Nov 2026 15:10:35 +0000</pubDate>
      <link>https://dev.to/kbytech/expiring-untagged-ecr-images-deletes-the-digest-an-ecs-service-still-runs-and-new-tasks-fail-to-39a3</link>
      <guid>https://dev.to/kbytech/expiring-untagged-ecr-images-deletes-the-digest-an-ecs-service-still-runs-and-new-tasks-fail-to-39a3</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://www.kbytechnologies.com/config-traps/ecr-lifecycle-untagged-images-expire-ecs-service-digest" rel="noopener noreferrer"&gt;KBY Technologies&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you run services on ECS and use ECR lifecycle rules to keep a registry tidy, this is the check we would run before your next cleanup-rule change: whether any service is pinned to a digest that has lost its tag. We cover the read-only commands that confirm it and the order for a safe fix.&lt;/p&gt;




&lt;h2&gt;
  
  
  Symptom
&lt;/h2&gt;

&lt;p&gt;New Amazon ECS tasks stop with &lt;code&gt;CannotPullContainerError: pull image manifest has been retried 5 time(s): failed to resolve ref&lt;/code&gt;, while the tasks that were already running stay healthy. If the Amazon ECR lifecycle rules changed recently, check first for a rule that expires untagged images. The service is pinned to an image digest, that digest lost its tag when the pipeline pushed a newer image under the same tag, and the rule then deleted it. The fix is to deploy a revision that names a unique tag or digest that exists, then rewrite the lifecycle policy so it never selects an image a service can still start. Do not start by disabling version consistency or by forcing a redeploy of &lt;code&gt;:latest&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The change behind it is routine: someone adds a cleanup rule close to AWS’s own example that keeps one untagged image and expires the rest, and nothing fails for hours or days. Then a scale-out or a replaced task needs one more copy of the container, and it cannot start. Running tasks do not pull again, so the service looks partly healthy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the cleanup rule looks safe
&lt;/h2&gt;

&lt;p&gt;An untagged image looks like an orphan: &lt;code&gt;aws ecr list-images&lt;/code&gt; shows it with a digest and no tags. In a repository with mutable tags, though, every push of &lt;code&gt;:latest&lt;/code&gt;, &lt;code&gt;:prod&lt;/code&gt; or &lt;code&gt;:main&lt;/code&gt; moves that tag to the new image. The image the service was deployed from keeps its digest, but unless it carries another tag it is now untagged, and an untagged rule selects it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Root Cause
&lt;/h2&gt;

&lt;p&gt;ECS starts every task in a service from one image digest, and the cleanup rule deleted that digest. By default ECS resolves the tag in the task definition to a digest: for a service, the first task the scheduler starts during a deployment establishes the digest, and ECS then uses that digest to start every other desired task and for future service updates, so every task in the service runs an identical image. AWS’s CannotPullContainer troubleshooting page states the consequence plainly: ECS forces image version stability, and if the original image is no longer available you get this error.&lt;/p&gt;

&lt;p&gt;On the registry side, a lifecycle rule can select &lt;code&gt;untagged&lt;/code&gt; images by count or by days since push, the &lt;code&gt;expire&lt;/code&gt; action deletes them, and ECR expires matching images within 24 hours of them meeting the criteria. Nothing in that evaluation asks ECS whether a service still runs a digest.&lt;/p&gt;

&lt;h2&gt;
  
  
  Impact
&lt;/h2&gt;

&lt;p&gt;A service pinned to an expired digest cannot start a new task until it gets a new deployment. That bites during a scale-out under load or when a failed task is replaced. If the repository replicates deletions to another Region or account, ECR replicates the lifecycle deletion there too, so a standby Region can lose the same image. The &lt;code&gt;expire&lt;/code&gt; action deletes the image, so the only way back is to push it again from a build you still have.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two shortcuts that make it worse
&lt;/h2&gt;

&lt;p&gt;The first is to set &lt;code&gt;versionConsistency&lt;/code&gt; to &lt;code&gt;disabled&lt;/code&gt; on the container. ECS then stops resolving the tag to a digest and starts tasks from the original image URI, so new tasks start again. But each task now pulls whatever the tag points to at the moment it starts. Tasks in one service can run different builds, and anything pushed to that tag goes live on the next scale-out without a deployment.&lt;/p&gt;

&lt;p&gt;The second is to force a new deployment of the same task definition. It works, because a new deployment establishes updated digests for new tasks, but it ships whatever image the tag points to now, which may be a build that never went through the checks the running release did. Use it only once you know the current image under the tag is the one you want. Deleting the lifecycle policy outright stops further deletions, but it cannot bring the expired image back and it leaves every old build in the registry still pullable; old builds carry their own risk, covered in &lt;a href="https://www.kbytechnologies.com/config-traps/ecr-scan-on-push-leaves-old-container-images-unscanned" rel="noopener noreferrer"&gt;why scan-on-push leaves older images unscanned&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to confirm the pinned digest is gone
&lt;/h2&gt;

&lt;p&gt;These checks are read-only. Replace &lt;code&gt;prod&lt;/code&gt;, &lt;code&gt;web&lt;/code&gt; and the ARNs with your own.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Find the task definition new tasks are started from. The deployment with status &lt;code&gt;PRIMARY&lt;/code&gt; is the most recent one.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ecs describe-services --cluster prod --services web \
  --query &lt;span class="s2"&gt;"services[0].deployments[].{status:status,taskDefinition:taskDefinition,running:runningCount,desired:desiredCount}"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Read why recent tasks stopped, and which image and digest they used. Run the same &lt;code&gt;describe-tasks&lt;/code&gt; against a running task to see the digest the service is pinned to.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ecs list-tasks --cluster prod --service-name web --desired-status STOPPED
aws ecs describe-tasks --cluster prod --tasks &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;task-arn&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; \
  --query &lt;span class="s2"&gt;"tasks[].{reason:stoppedReason,containers:containers[].{image:image,digest:imageDigest}}"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Ask ECR for that digest. &lt;code&gt;ImageNotFoundException&lt;/code&gt; confirms the image is gone. If it comes back with no &lt;code&gt;imageTags&lt;/code&gt;, it is next in line for any untagged rule.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ecr describe-images --repository-name web \
  --image-ids &lt;span class="nv"&gt;imageDigest&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;sha256:&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;digest&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Read the rule with &lt;code&gt;aws ecr get-lifecycle-policy --repository-name web&lt;/code&gt;. In CloudTrail, filter on the event name &lt;code&gt;PolicyExecutionEvent&lt;/code&gt;, which ECR records when a lifecycle rule expires images, to see when it ran. &lt;a href="https://www.kbytechnologies.com/graduate/cloud-infrastructure-and-operations/aws-cloudtrail-event-history-find-who-changed-security-group" rel="noopener noreferrer"&gt;Searching CloudTrail Event history by event name&lt;/a&gt; works the same way here.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Correction
&lt;/h2&gt;

&lt;p&gt;Deploy a uniquely tagged image first and change the lifecycle policy second, so the service always has an image it can start. Before you begin, you need push rights to the repository, permission to register task definitions and update the service, and the build of the release that should be running.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Save what you are about to change: the current lifecycle policy text and the current task definition.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ecr get-lifecycle-policy --repository-name web \
  --query lifecyclePolicyText --output text &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; lifecycle-before.json
aws ecs describe-task-definition --task-definition web:42 &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; taskdef-42.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Push the release you want under a unique tag, such as a version number or commit ID, not under &lt;code&gt;:latest&lt;/code&gt;. AWS’s own guidance for this error is to change the task definition from &lt;code&gt;:latest&lt;/code&gt; to a specific version.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Register a new task definition revision whose &lt;code&gt;image&lt;/code&gt; is that tag, in the form &lt;code&gt;repository-url/image:tag&lt;/code&gt;, or a digest in the form &lt;code&gt;repository-url/image@digest&lt;/code&gt;. Then deploy it:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ecs update-service --cluster prod --service web --task-definition web:43
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Stop &lt;span class="k"&gt;if&lt;/span&gt; new tasks fail again with the same error, and check the tag exists with &lt;span class="sb"&gt;`describe-images`&lt;/span&gt; before you retry.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Write the new lifecycle policy and preview it before applying it. Under unique tags, deployed images keep their tags, so the untagged rule only reaches builds nothing deploys, and the tagged rule keeps enough releases to roll back to.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"rules"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"rulePriority"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Keep the last 20 releases"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"selection"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"tagStatus"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"tagged"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"tagPatternList"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"v*"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"countType"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"imageCountMoreThan"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"countNumber"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"expire"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"rulePriority"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Expire untagged builds after 14 days"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"selection"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"tagStatus"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"untagged"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"countType"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"sinceImagePushed"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"countUnit"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"days"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"countNumber"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"expire"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;aws&lt;/span&gt; &lt;span class="n"&gt;ecr&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="err"&gt;-&lt;/span&gt;&lt;span class="n"&gt;lifecycle&lt;/span&gt;&lt;span class="err"&gt;-&lt;/span&gt;&lt;span class="n"&gt;policy&lt;/span&gt;&lt;span class="err"&gt;-&lt;/span&gt;&lt;span class="n"&gt;preview&lt;/span&gt; &lt;span class="err"&gt;--&lt;/span&gt;&lt;span class="n"&gt;repository&lt;/span&gt;&lt;span class="err"&gt;-&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="n"&gt;web&lt;/span&gt; &lt;span class="err"&gt;\&lt;/span&gt;
  &lt;span class="err"&gt;--&lt;/span&gt;&lt;span class="n"&gt;lifecycle&lt;/span&gt;&lt;span class="err"&gt;-&lt;/span&gt;&lt;span class="n"&gt;policy&lt;/span&gt;&lt;span class="err"&gt;-&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="err"&gt;//&lt;/span&gt;&lt;span class="n"&gt;policy&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;
&lt;span class="n"&gt;aws&lt;/span&gt; &lt;span class="n"&gt;ecr&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="err"&gt;-&lt;/span&gt;&lt;span class="n"&gt;lifecycle&lt;/span&gt;&lt;span class="err"&gt;-&lt;/span&gt;&lt;span class="n"&gt;policy&lt;/span&gt;&lt;span class="err"&gt;-&lt;/span&gt;&lt;span class="n"&gt;preview&lt;/span&gt; &lt;span class="err"&gt;--&lt;/span&gt;&lt;span class="n"&gt;repository&lt;/span&gt;&lt;span class="err"&gt;-&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="n"&gt;web&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Wait &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="sb"&gt;`status`&lt;/span&gt; to &lt;span class="nb"&gt;read&lt;/span&gt; &lt;span class="sb"&gt;`COMPLETE`&lt;/span&gt;, &lt;span class="k"&gt;then&lt;/span&gt; compare every digest &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="sb"&gt;`previewResults`&lt;/span&gt; with the digests your services run. If any matches, change the rule and preview again. Only &lt;span class="k"&gt;then&lt;/span&gt; apply it with &lt;span class="sb"&gt;`aws ecr put-lifecycle-policy --repository-name web --lifecycle-policy-text file://policy.json`&lt;/span&gt;.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Validation
&lt;/h2&gt;

&lt;p&gt;The fix holds when new tasks start from an image ECR still has, under a tag the policy will not expire.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;describe-services&lt;/code&gt; shows the new revision on the &lt;code&gt;PRIMARY&lt;/code&gt; deployment, with &lt;code&gt;runningCount&lt;/code&gt; equal to &lt;code&gt;desiredCount&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;describe-tasks&lt;/code&gt; on a new task shows an &lt;code&gt;imageDigest&lt;/code&gt; that &lt;code&gt;describe-images&lt;/code&gt; returns with your unique tag in &lt;code&gt;imageTags&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A fresh lifecycle preview lists none of the digests your services use.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Rollback
&lt;/h2&gt;

&lt;p&gt;Each step below can be reversed; an expired image can only be pushed again from a build you still have.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Service: roll back with &lt;code&gt;update-service&lt;/code&gt; to the previous revision that names a unique tag. Rolling back to the old &lt;code&gt;:latest&lt;/code&gt; revision does not bring back the old image: the new deployment resolves the tag again and pins whatever it points to now.&lt;/li&gt;
&lt;li&gt;Lifecycle policy: restore the saved text with &lt;code&gt;aws ecr put-lifecycle-policy --repository-name web --lifecycle-policy-text file://lifecycle-before.json&lt;/code&gt;. Restoring the policy does not restore images it already expired.&lt;/li&gt;
&lt;li&gt;Tag immutability, if you turn it on below: set it back with &lt;code&gt;aws ecr put-image-tag-mutability --repository-name web --image-tag-mutability MUTABLE&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Stop it happening on the next release
&lt;/h2&gt;

&lt;p&gt;Deploy from unique tags and make them immutable, so a release tag can never be moved to a different image. ECR can keep one tag such as &lt;code&gt;latest&lt;/code&gt; movable while every other tag is locked; pushing an existing locked tag then fails with &lt;code&gt;ImageTagAlreadyExistsException&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ecr put-image-tag-mutability --repository-name web \
  --image-tag-mutability IMMUTABLE_WITH_EXCLUSION \
  --image-tag-mutability-exclusion-filters &lt;span class="nv"&gt;filterType&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;WILDCARD,filter=latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Preview every lifecycle change against the digests your services run, and remember that a lifecycle policy only acts in the Region where you create it unless deletions are replicated. Be careful with &lt;code&gt;sinceImagePulled&lt;/code&gt; rules: ECR updates the last recorded pull time on pulls (at least once every 24 hours), but a stable service that has not started a task recently has not pulled either, so its image can look idle while it is still the only one the service can start.&lt;/p&gt;




&lt;p&gt;&lt;a href="https://www.kbytechnologies.com/config-traps/ecr-lifecycle-untagged-images-expire-ecs-service-digest?utm_source=devto&amp;amp;utm_medium=syndication" rel="noopener noreferrer"&gt;Read the original on KBY Technologies&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>devops</category>
      <category>containers</category>
      <category>security</category>
    </item>
    <item>
      <title>Turning On ECR Tag Immutability Breaks Pipelines That Re-Push the latest Tag</title>
      <dc:creator>KBY Technologies</dc:creator>
      <pubDate>Wed, 18 Nov 2026 13:45:19 +0000</pubDate>
      <link>https://dev.to/kbytech/turning-on-ecr-tag-immutability-breaks-pipelines-that-re-push-the-latest-tag-347j</link>
      <guid>https://dev.to/kbytech/turning-on-ecr-tag-immutability-breaks-pipelines-that-re-push-the-latest-tag-347j</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://www.kbytechnologies.com/config-traps/ecr-tag-immutability-breaks-pipelines-latest-tag" rel="noopener noreferrer"&gt;KBY Technologies&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you push images to ECR from CI and a security review has asked you to make the repository immutable, this is the part we would check in your pipeline first: whether anything pushes the same tag twice. We walk through the exclusion that keeps release tags locked while the build goes green, and the read-only checks to run before you change anything.&lt;/p&gt;




&lt;p&gt;Switching an Amazon ECR repository to &lt;code&gt;IMMUTABLE&lt;/code&gt; stops every pipeline that pushes the same tag twice, and a pipeline that pushes &lt;code&gt;latest&lt;/code&gt; on every build does exactly that. From the moment the setting changes, ECR answers a push of an existing tag with &lt;code&gt;ImageTagAlreadyExistsException&lt;/code&gt;: “The specified image is tagged with a tag that already exists. The repository is configured for tag immutability.” The fix is not to turn immutability off. Set the repository to &lt;code&gt;IMMUTABLE_WITH_EXCLUSION&lt;/code&gt; with a single &lt;code&gt;WILDCARD&lt;/code&gt; filter for &lt;code&gt;latest&lt;/code&gt;, so release tags stay protected and the build goes green, then move the pipeline to a unique tag per build and drop the exclusion once nothing depends on &lt;code&gt;latest&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Symptom
&lt;/h2&gt;

&lt;p&gt;The image push step fails with &lt;code&gt;ImageTagAlreadyExistsException&lt;/code&gt; on the first build after the repository setting changed. The build and test stages pass, the image exists locally, and nothing in the pipeline definition changed. The PutImage API documents the error as HTTP 400 with the message quoted above. If the pipeline pushes a unique tag first and &lt;code&gt;latest&lt;/code&gt; second, the unique tag lands and only the second push fails, which makes it look like an intermittent registry fault rather than a setting.&lt;/p&gt;

&lt;p&gt;Repositories that serve a pull through cache rule are a related case. AWS recommends &lt;code&gt;Mutable&lt;/code&gt; for those so that ECR can update cached images, so a blanket “make every repository immutable” change can stop cached images refreshing as well as breaking builds.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why it looks safe to switch on
&lt;/h2&gt;

&lt;p&gt;Tag immutability is usually turned on as a hardening task, often after a scanner or audit flags mutable repositories. The mental model is “release tags can no longer be overwritten”, and that part is true. What is easy to miss is that plain &lt;code&gt;IMMUTABLE&lt;/code&gt; makes no distinction between a release tag such as &lt;code&gt;v2.3.1&lt;/code&gt; and a moving tag such as &lt;code&gt;latest&lt;/code&gt;, &lt;code&gt;main&lt;/code&gt; or &lt;code&gt;dev&lt;/code&gt;. The ECR user guide says it directly: tag immutability affects all tags. A pipeline written to push &lt;code&gt;latest&lt;/code&gt; after every merge has always relied on overwriting it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Root cause
&lt;/h2&gt;

&lt;p&gt;The repository’s &lt;code&gt;imageTagMutability&lt;/code&gt; setting decides whether any existing tag can be pointed at a new image. With &lt;code&gt;MUTABLE&lt;/code&gt;, image tags can be overwritten. With &lt;code&gt;IMMUTABLE&lt;/code&gt;, every tag in the repository is immutable, and pushing an image with a tag that is already in the repository is rejected. The first push of &lt;code&gt;latest&lt;/code&gt; after the change is refused because &lt;code&gt;latest&lt;/code&gt; already exists from the previous build.&lt;/p&gt;

&lt;p&gt;Since ECR added exclusion filters there are four values, not two: &lt;code&gt;MUTABLE&lt;/code&gt;, &lt;code&gt;IMMUTABLE&lt;/code&gt;, &lt;code&gt;IMMUTABLE_WITH_EXCLUSION&lt;/code&gt; and &lt;code&gt;MUTABLE_WITH_EXCLUSION&lt;/code&gt;. &lt;code&gt;IMMUTABLE_WITH_EXCLUSION&lt;/code&gt; keeps the repository immutable but lets the tags that match a filter be updated; &lt;code&gt;MUTABLE_WITH_EXCLUSION&lt;/code&gt; does the reverse and locks only the matching tags. Each filter has &lt;code&gt;filterType&lt;/code&gt; &lt;code&gt;WILDCARD&lt;/code&gt; and a &lt;code&gt;filter&lt;/code&gt; of 1 to 128 characters drawn from letters, digits, &lt;code&gt;.&lt;/code&gt;, &lt;code&gt;_&lt;/code&gt;, &lt;code&gt;*&lt;/code&gt; and &lt;code&gt;-&lt;/code&gt;, and a repository takes between one and five filters.&lt;/p&gt;

&lt;h2&gt;
  
  
  Impact
&lt;/h2&gt;

&lt;p&gt;Every pipeline that re-pushes a moving tag to the repository stops delivering images until the setting or the pipeline changes. Deployments that pull &lt;code&gt;latest&lt;/code&gt; keep running the last image that was successfully pushed, so the service looks healthy while new code never arrives.&lt;/p&gt;

&lt;p&gt;Under pressure the quick fix is &lt;code&gt;put-image-tag-mutability --image-tag-mutability MUTABLE&lt;/code&gt;. It unblocks the build in seconds and removes the protection for every tag, including the release tags the change was meant to protect: any principal allowed to push can again point &lt;code&gt;v2.3.1&lt;/code&gt; at a different image. A filter of &lt;code&gt;*&lt;/code&gt; under &lt;code&gt;IMMUTABLE_WITH_EXCLUSION&lt;/code&gt; would match every tag and amount to the same thing. Nothing in a green build log shows that the protection has gone. If you need to find who changed the setting in the first place, the CloudTrail steps in &lt;a href="https://www.kbytechnologies.com/graduate/cloud-infrastructure-and-operations/aws-cloudtrail-event-history-find-who-changed-security-group" rel="noopener noreferrer"&gt;finding who changed a security group with CloudTrail Event history&lt;/a&gt; work the same way for ECR, because CloudTrail records every ECR API call.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to confirm it without changing anything
&lt;/h2&gt;

&lt;p&gt;Two read-only calls settle the diagnosis. First, read the repository setting and any filters:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ecr describe-repositories --repository-names &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;repo&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; \
  --query &lt;span class="s2"&gt;"repositories[].[repositoryName,imageTagMutability,imageTagMutabilityExclusionFilters]"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An answer of &lt;code&gt;IMMUTABLE&lt;/code&gt;, or &lt;code&gt;IMMUTABLE_WITH_EXCLUSION&lt;/code&gt; with no filter that matches the tag the pipeline pushes, confirms the cause. Second, check that the tag already exists and which image holds it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ecr describe-images --repository-name &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;repo&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; --image-ids &lt;span class="nv"&gt;imageTag&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output shows the &lt;code&gt;imageDigest&lt;/code&gt;, the &lt;code&gt;imageTags&lt;/code&gt; on that image and &lt;code&gt;imagePushedAt&lt;/code&gt;. A push time that matches the last green build, before the setting changed, is the image the failing push is trying to replace. To see when the setting changed and by whom, look up the event in the repository’s Region; Event history covers the last 90 days:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws cloudtrail lookup-events \
  --lookup-attributes &lt;span class="nv"&gt;AttributeKey&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;EventName,AttributeValue=PutImageTagMutability
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Correction
&lt;/h2&gt;

&lt;p&gt;Unblock the pipeline with a one-tag exclusion first, then remove the pipeline’s dependence on the moving tag. Run every step in the repository’s own Region with a role that can call &lt;code&gt;ecr:PutImageTagMutability&lt;/code&gt;, and try it on a non-production repository first.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Record the current state.&lt;/strong&gt; Save the setting so rollback has an exact target:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ecr describe-repositories --repository-names &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;repo&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; ecr-mutability-before.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Exclude only the moving tag.&lt;/strong&gt; Precondition: the backup file exists and shows &lt;code&gt;IMMUTABLE&lt;/code&gt; or &lt;code&gt;IMMUTABLE_WITH_EXCLUSION&lt;/code&gt;. The call carries the repository’s whole filter list, so include any existing filters you want to keep.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ecr put-image-tag-mutability --repository-name &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;repo&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; \
  --image-tag-mutability IMMUTABLE_WITH_EXCLUSION \
  --image-tag-mutability-exclusion-filters &lt;span class="nv"&gt;filterType&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;WILDCARD,filter=latest
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;The response echoes &lt;code&gt;imageTagMutability&lt;/code&gt; and the filter list. Re-run the failed build: the &lt;code&gt;latest&lt;/code&gt; push should now succeed, and every other tag stays immutable.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Give every build a unique tag.&lt;/strong&gt; Change the pipeline to push a tag that is never reused, such as the commit SHA or build number, alongside &lt;code&gt;latest&lt;/code&gt;. Point deployments at that tag, or at the image digest, rather than at &lt;code&gt;latest&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Drop the exclusion when nothing reads latest.&lt;/strong&gt; Precondition: no task definition, manifest or script still pulls &lt;code&gt;latest&lt;/code&gt; and the pipeline no longer pushes it. Then set plain immutability:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws ecr put-image-tag-mutability --repository-name &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;repo&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; --image-tag-mutability IMMUTABLE
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Keep the exclusion as narrow as the tag name allows. A filter such as &lt;code&gt;dev-*&lt;/code&gt; is fine for a family of moving tags; a filter that also matches release names defeats the point.&lt;/p&gt;

&lt;h2&gt;
  
  
  Verification
&lt;/h2&gt;

&lt;p&gt;The fix holds when a moving-tag push succeeds and a release-tag overwrite is still refused. Run &lt;code&gt;describe-repositories&lt;/code&gt; again and confirm &lt;code&gt;imageTagMutability&lt;/code&gt; and the filter list read exactly as intended. Run &lt;code&gt;describe-images --image-ids imageTag=latest&lt;/code&gt; and confirm &lt;code&gt;imagePushedAt&lt;/code&gt; now matches the new build. In a non-production repository, push a second image under an existing release tag: it should still fail with &lt;code&gt;ImageTagAlreadyExistsException&lt;/code&gt;. If it succeeds, a filter is wider than you meant.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rollback
&lt;/h2&gt;

&lt;p&gt;Rollback is one call that restores the value saved in &lt;code&gt;ecr-mutability-before.json&lt;/code&gt;. If the repository was &lt;code&gt;IMMUTABLE&lt;/code&gt; before step 2, run &lt;code&gt;put-image-tag-mutability --image-tag-mutability IMMUTABLE&lt;/code&gt; with no filters; if it already had filters, send the same value and the same filter list. Restoring &lt;code&gt;IMMUTABLE&lt;/code&gt; brings the failing &lt;code&gt;latest&lt;/code&gt; push back until the pipeline stops pushing that tag. AWS documents the setting’s effect on pushes, not on images already stored. Stop and escalate if the backup shows &lt;code&gt;MUTABLE&lt;/code&gt;: that repository was never immutable and the failure has another cause.&lt;/p&gt;

&lt;h2&gt;
  
  
  Stop it happening on the next repository
&lt;/h2&gt;

&lt;p&gt;Before switching a repository to immutable, search the pipelines that push to it for tags that are reused, and set the exclusion in the same change. New repositories can be created with the right setting from the start using &lt;code&gt;create-repository --image-tag-mutability IMMUTABLE_WITH_EXCLUSION --image-tag-mutability-exclusion-filters filterType=WILDCARD,filter=latest&lt;/code&gt;. Leave pull through cache repositories mutable, as AWS recommends. Immutability fixes what a tag points to, not what is inside the image, so pair it with scanning; &lt;a href="https://www.kbytechnologies.com/config-traps/ecr-scan-on-push-leaves-old-container-images-unscanned" rel="noopener noreferrer"&gt;scan on push leaves images pushed before it was enabled unscanned&lt;/a&gt;, and &lt;a href="https://www.kbytechnologies.com/config-traps/ecr-cross-account-pull-policies-without-source-conditions" rel="noopener noreferrer"&gt;cross-account pull policies need source conditions&lt;/a&gt; to keep the right accounts reading those images.&lt;/p&gt;




&lt;p&gt;&lt;a href="https://www.kbytechnologies.com/config-traps/ecr-tag-immutability-breaks-pipelines-latest-tag?utm_source=devto&amp;amp;utm_medium=syndication" rel="noopener noreferrer"&gt;Read the original on KBY Technologies&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>devops</category>
      <category>containers</category>
      <category>security</category>
    </item>
    <item>
      <title>Adding an Environment to a GitHub Actions Job Changes the OIDC Subject and Breaks Azure Federated Login</title>
      <dc:creator>KBY Technologies</dc:creator>
      <pubDate>Tue, 17 Nov 2026 10:50:09 +0000</pubDate>
      <link>https://dev.to/kbytech/adding-an-environment-to-a-github-actions-job-changes-the-oidc-subject-and-breaks-azure-federated-492p</link>
      <guid>https://dev.to/kbytech/adding-an-environment-to-a-github-actions-job-changes-the-oidc-subject-and-breaks-azure-federated-492p</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://www.kbytechnologies.com/config-traps/github-actions-environment-oidc-subject-breaks-azure-federated-login" rel="noopener noreferrer"&gt;KBY Technologies&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When a GitHub Actions job references an environment, GitHub changes the subject (&lt;code&gt;sub&lt;/code&gt;) claim in the job’s OIDC token. A job without an environment, triggered by a push, sends &lt;code&gt;repo:ORG/REPO:ref:refs/heads/BRANCH&lt;/code&gt;. Add &lt;code&gt;environment: production&lt;/code&gt; to the same job and it sends &lt;code&gt;repo:ORG/REPO:environment:production&lt;/code&gt; instead, on every branch. Microsoft Entra ID only exchanges the token when its issuer and subject exactly match a federated identity credential on the app registration or user-assigned managed identity, so a credential written for the branch stops matching and the &lt;code&gt;azure/login&lt;/code&gt; step fails. The fix is to add a second credential with the exact environment subject, let it propagate, and only then merge the workflow change. A standard federated credential takes no wildcards or branch patterns, so it cannot cover both subjects at once.&lt;/p&gt;

&lt;h2&gt;
  
  
  Symptom
&lt;/h2&gt;

&lt;p&gt;A deployment that has authenticated to Azure for months starts failing at the Azure Login step on the first run after someone adds an environment to the deploy job, usually to gain required reviewers or environment secrets. Nothing changed in Azure: the app registration, its role assignments and the client, tenant and subscription IDs stored in GitHub are all the same. The token exchange is refused because no federated identity credential matches the presented token. Microsoft documents the message &lt;code&gt;AADSTS70021: No matching federated identity record found for presented assertion&lt;/code&gt; for a request that no credential matches yet, so look for it in the Azure Login output. Jobs in the same workflow that do not reference the environment keep working, which makes the failure look intermittent or job-specific.&lt;/p&gt;

&lt;h2&gt;
  
  
  False Assumption
&lt;/h2&gt;

&lt;p&gt;The natural assumption is that the federated credential trusts “the main branch of this repository”, so any job running from &lt;code&gt;main&lt;/code&gt; is covered. It does not. The credential stores one literal subject string, and GitHub builds that string from the job’s context. GitHub documents that the branch name appears in the subject only if the job does not reference an environment and the workflow is not triggered by a pull request. Once an environment is referenced, the branch is no longer in the subject at all.&lt;/p&gt;

&lt;h2&gt;
  
  
  Root Cause
&lt;/h2&gt;

&lt;p&gt;The subject GitHub sends depends on the job, not on the repository, and Entra compares it character for character. GitHub assembles the default subject in this order of precedence:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Job references an environment: &lt;code&gt;repo:ORG-NAME/REPO-NAME:environment:ENVIRONMENT-NAME&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;No environment, pull request event: &lt;code&gt;repo:ORG-NAME/REPO-NAME:pull_request&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;No environment, branch or tag: &lt;code&gt;repo:ORG-NAME/REPO-NAME:ref:refs/heads/BRANCH-NAME&lt;/code&gt; or &lt;code&gt;:ref:refs/tags/TAG-NAME&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On the Entra side, the issuer and subject of the credential must match the &lt;code&gt;iss&lt;/code&gt; and &lt;code&gt;sub&lt;/code&gt; claims of the incoming token, the issuer and subject pair must be unique on the app, and wildcard characters are not supported in any property of a standard credential. Microsoft also notes that a credential with the wrong subject is created successfully, with no error, so the mismatch only surfaces when a workflow tries to exchange a token.&lt;/p&gt;

&lt;h2&gt;
  
  
  Impact
&lt;/h2&gt;

&lt;p&gt;Every run of the changed job loses access to Azure until a matching credential exists, which in practice means a blocked production deployment rather than a security exposure. The pressure that follows is the larger risk: the quickest-looking workarounds are removing the environment again, which also removes its approval gate, or creating client secrets on the app, which brings back the long-lived credential federation was meant to remove. Getting the environment credential right is also the safer end state, because a &lt;a href="https://www.kbytechnologies.com/config-traps/branch-scoped-federated-credential-subjects-grant-azure-token-exchange" rel="noopener noreferrer"&gt;branch-scoped subject lets every workflow on that branch exchange a token&lt;/a&gt;, whereas an environment subject can sit behind required reviewers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Diagnosis
&lt;/h2&gt;

&lt;p&gt;Compare the subject GitHub sends with the subjects Entra holds. Both checks are read-only.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; List the credentials on the app registration and save the output as your backup. The &lt;code&gt;--id&lt;/code&gt; parameter takes the app’s object ID, application (client) ID or identifier URI: &lt;code&gt;az ad app federated-credential list --id &amp;lt;app-id&amp;gt; &amp;gt; fic-backup.json&lt;/code&gt;. The deploy credential will show a subject such as &lt;code&gt;repo:contoso/web-app:ref:refs/heads/main&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt; Read the subject the job actually sends. GitHub’s &lt;code&gt;github/actions-oidc-debugger&lt;/code&gt; action prints the claims in the job’s token; run it in a job with the same &lt;code&gt;environment:&lt;/code&gt; value and &lt;code&gt;id-token: write&lt;/code&gt; permission. Expect &lt;code&gt;sub&lt;/code&gt; to read &lt;code&gt;repo:contoso/web-app:environment:production&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt; Check the repository’s subject format. Repositories created after 15 July 2026, and older ones that opted in or were renamed or transferred after that date, use GitHub’s immutable format, &lt;code&gt;repo:OWNER@OWNER-ID/REPO@REPO-ID:...&lt;/code&gt;. Also check whether the organisation or repository has a customised subject template, which replaces the default format entirely.&lt;/li&gt;
&lt;li&gt; Rule out the other parts of the match. The issuer should be &lt;code&gt;https://token.actions.githubusercontent.com&lt;/code&gt; and the audience &lt;code&gt;api://AzureADTokenExchange&lt;/code&gt;, which is the &lt;code&gt;azure/login&lt;/code&gt; default for public clouds; an &lt;a href="https://www.kbytechnologies.com/config-traps/federated-credential-audience-mismatch-azure-workload-identity" rel="noopener noreferrer"&gt;audience mismatch blocks the exchange in the same quiet way&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If the debugger shows an environment subject and the list shows only a ref subject, you have found the trap.&lt;/p&gt;

&lt;h2&gt;
  
  
  Correction
&lt;/h2&gt;

&lt;p&gt;Add a credential for the environment subject and leave the branch credential alone. Creating, updating or deleting a federated identity credential needs ownership of the app or the Application Administrator, Cloud Application Administrator, Global Administrator or Hybrid Identity Administrator role.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Precondition: confirm the app holds fewer than 20 federated identity credentials, the documented maximum per application or user-assigned managed identity, and that &lt;code&gt;fic-backup.json&lt;/code&gt; from the diagnosis step exists.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Write &lt;code&gt;credential.json&lt;/code&gt; with a URL-friendly name, the GitHub issuer, the exact subject from the debugger output and the default audience:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"github-web-app-production"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"issuer"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://token.actions.githubusercontent.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"subject"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"repo:contoso/web-app:environment:production"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"audiences"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"api://AzureADTokenExchange"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create it: &lt;code&gt;az ad app federated-credential create --id &amp;lt;app-id&amp;gt; --parameters credential.json&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Wait several minutes before testing. Microsoft documents that a new credential takes time to propagate and that requests made too early can fail with &lt;code&gt;AADSTS70021&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Merge the workflow change that adds &lt;code&gt;environment: production&lt;/code&gt; to the job.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In the Entra admin center the same credential is added under the app’s &lt;strong&gt;Certificates &amp;amp; secrets&lt;/strong&gt;, &lt;strong&gt;Federated credentials&lt;/strong&gt; tab, choosing the &lt;strong&gt;GitHub actions deploying Azure resources&lt;/strong&gt; scenario and an &lt;strong&gt;Entity type&lt;/strong&gt; of &lt;strong&gt;Environment&lt;/strong&gt;. The portal fills in the subject; compare it with the debugger output before saving, particularly for repositories on the immutable ID format.&lt;/p&gt;

&lt;h2&gt;
  
  
  Validation
&lt;/h2&gt;

&lt;p&gt;Validation succeeds when the environment job logs in to Azure and nothing else on the app has changed.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;az ad app federated-credential show --id &amp;lt;app-id&amp;gt; --federated-credential-id github-web-app-production&lt;/code&gt; returns the subject exactly as the debugger printed it, including case.&lt;/li&gt;
&lt;li&gt;The next run of the job passes the Azure Login step, and an &lt;code&gt;az account show&lt;/code&gt; step prints the expected subscription.&lt;/li&gt;
&lt;li&gt;A fresh &lt;code&gt;az ad app federated-credential list&lt;/code&gt; differs from &lt;code&gt;fic-backup.json&lt;/code&gt; only by the new credential.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Rollback
&lt;/h2&gt;

&lt;p&gt;Rollback is a workflow revert, because the original branch credential was never touched. Revert the commit that added &lt;code&gt;environment:&lt;/code&gt; to the job; it then sends the ref subject again and the existing credential matches. If the new credential is wrong or unwanted, remove only that one with &lt;code&gt;az ad app federated-credential delete --id &amp;lt;app-id&amp;gt; --federated-credential-id github-web-app-production&lt;/code&gt; and compare a fresh list with &lt;code&gt;fic-backup.json&lt;/code&gt;. Do not delete the branch credential as part of this change; once every job that needs it has moved to environments, removing it is a separate, reviewed decision.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prevention: Create the Azure Credential Before the Environment Reaches the Workflow
&lt;/h2&gt;

&lt;p&gt;Treat any change to a job’s trigger or &lt;code&gt;environment:&lt;/code&gt; key as a change to its Azure identity, and review it alongside the federated credentials:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add the matching credential first, wait for propagation, then merge the workflow change; GitHub gives the same advice for subject customisation templates.&lt;/li&gt;
&lt;li&gt;Prefer one environment credential per deployment target over one credential per branch. Microsoft recommends specifying an environment when an on-push workflow runs against many branches or tags, and it keeps you well inside the 20-credential limit.&lt;/li&gt;
&lt;li&gt;Watch for names that change the subject: environment names with a colon are encoded as &lt;code&gt;%3A&lt;/code&gt;, and a repository rename or transfer can move it to the immutable ID format.&lt;/li&gt;
&lt;li&gt;Do not reach for a pattern to close the gap. Standard credentials match exactly; flexible federated identity credentials, still in preview, accept a &lt;code&gt;matches&lt;/code&gt; expression on &lt;code&gt;sub&lt;/code&gt; but must also pin &lt;code&gt;repository_id&lt;/code&gt; or &lt;code&gt;repository_owner_id&lt;/code&gt;, and &lt;a href="https://www.kbytechnologies.com/config-traps/wildcard-federated-credentials-widen-uami-blast-radius" rel="noopener noreferrer"&gt;wildcard federated credentials widen the blast radius&lt;/a&gt; of the identity they protect.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Before closing the change, confirm the deploy job’s subject, the credential list and the role assignments on the app all describe the same environment, so the next safe decision, retiring the branch credential, can be made from evidence rather than guesswork.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This is one of KBY Technologies' Config Traps: settings that look right and quietly break something. Read the original, with its fix commands, &lt;a href="https://www.kbytechnologies.com/config-traps/github-actions-environment-oidc-subject-breaks-azure-federated-login?utm_source=devto&amp;amp;utm_medium=syndication&amp;amp;utm_campaign=config-traps&amp;amp;utm_content=github-actions-environment-oidc-subject-breaks-azure-federated-login" rel="noopener noreferrer"&gt;on kbytechnologies.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>azure</category>
      <category>github</category>
      <category>devops</category>
      <category>security</category>
    </item>
    <item>
      <title>Why Your Postgres Is Idle But Your API Is Timing Out (PgBouncer Pool Exhaustion, Explained)</title>
      <dc:creator>KBY Technologies</dc:creator>
      <pubDate>Thu, 16 Jul 2026 16:10:30 +0000</pubDate>
      <link>https://dev.to/kbytech/why-your-postgres-is-idle-but-your-api-is-timing-out-pgbouncer-pool-exhaustion-explained-48am</link>
      <guid>https://dev.to/kbytech/why-your-postgres-is-idle-but-your-api-is-timing-out-pgbouncer-pool-exhaustion-explained-48am</guid>
      <description>&lt;p&gt;Ever had an incident where latency on a trivial &lt;code&gt;SELECT&lt;/code&gt; spikes from a few milliseconds to several seconds, CPU on the Postgres box is basically flat, and there's no slow query or missing index anywhere in sight?&lt;/p&gt;

&lt;p&gt;That's not a database problem. That's &lt;strong&gt;connection pool exhaustion&lt;/strong&gt; at the PgBouncer layer — and it's one of the most common (and most misdiagnosed) production incidents in Postgres-backed systems.&lt;/p&gt;

&lt;p&gt;I just wrote a deep dive on this: how it happens, how to diagnose it live, and how to size your pool correctly instead of guessing. Here's the short version.&lt;/p&gt;

&lt;h2&gt;
  
  
  The core issue
&lt;/h2&gt;

&lt;p&gt;PgBouncer sits between potentially thousands of client connections and a small, fixed number of physical Postgres backends. That works fine — until something makes transactions hold connections longer than expected: a slow downstream API call, a lock wait, a runaway transaction. When that happens, the queue of waiting clients grows unbounded, and every request behind it pays the tax, even the fast ones.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pooling mode matters more than people think
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Session pooling&lt;/strong&gt; — 1:1 mapping, safest for compatibility, but a pool of 100 connections supports at most 100 concurrent clients. Full stop.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Transaction pooling&lt;/strong&gt; — what most production setups run. Connections are freed the instant a transaction commits, so you can multiplex hundreds of clients onto a handful of backends. The catch: anything session-scoped (&lt;code&gt;SET search_path&lt;/code&gt;, prepared statements, temp tables) becomes unreliable.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Statement pooling&lt;/strong&gt; — most aggressive, breaks multi-statement transactions, mostly used for read-only analytics.
Transaction mode is where exhaustion gets sneaky, because the pool &lt;em&gt;looks&lt;/em&gt; elastic. Teams assume Postgres's &lt;code&gt;max_connections&lt;/code&gt; is the real ceiling — it isn't. The real ceiling is how many transactions your application can hold open simultaneously.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Diagnosing it live
&lt;/h2&gt;

&lt;p&gt;Two commands tell you almost everything:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;psql -h 127.0.0.1 -p 6432 -U pgbadmin pgbouncer -c &lt;span class="s2"&gt;"SHOW POOLS;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If &lt;code&gt;cl_waiting&lt;/code&gt; is climbing while &lt;code&gt;sv_active&lt;/code&gt; is pinned at &lt;code&gt;pool_size&lt;/code&gt;, that's the signature: every server slot is occupied and clients are queuing.&lt;/p&gt;

&lt;p&gt;Then cross-reference with Postgres directly to find out &lt;em&gt;what's&lt;/em&gt; holding those slots hostage — usually a transaction left open across a network call (a classic ORM anti-pattern), or a lock wait cascading from a migration.&lt;/p&gt;

&lt;h2&gt;
  
  
  The usual culprit: idle-in-transaction leakage
&lt;/h2&gt;

&lt;p&gt;If your app opens a transaction, does a read, then awaits an external HTTP call before committing, that connection is unusable by anyone else for the entire duration of that call. Under load, this single pattern causes more exhaustion incidents than raw traffic volume ever does.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sizing the pool properly
&lt;/h2&gt;

&lt;p&gt;Little's Law gives a good starting point:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;required_connections = arrival_rate × average_transaction_duration
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But size for the tail, not the average — one slow query can distort your numbers badly. And resist the urge to just crank &lt;code&gt;default_pool_size&lt;/code&gt; up; more Postgres backends means more memory overhead and more lock contention, not a free win.&lt;/p&gt;




&lt;p&gt;I go into a lot more depth in the full article — reference PgBouncer config, the exact diagnostic queries, failover edge cases, and the security trade-offs of exposing the admin console. Worth a read if you've ever been paged for a "database is slow" incident that turned out not to be the database at all.&lt;/p&gt;

&lt;p&gt;👉 &lt;a href="https://www.kbytechnologies.com/systems-engineering/diagnosing-pgbouncer-pool-exhaustion-under-load" rel="noopener noreferrer"&gt;Full article: Diagnosing PgBouncer Pool Exhaustion Under Load&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Curious if others have run into the prepared-statement-caching gotcha under transaction pooling — that one bit me hard the first time I hit it. Drop your war stories below.&lt;/p&gt;

</description>
      <category>postgres</category>
      <category>devops</category>
      <category>database</category>
      <category>backend</category>
    </item>
  </channel>
</rss>
