[openssh-commits] [openssh] 04/13: upstream: Don't let AddKeysToAgent clobber keys already in the
git+noreply at mindrot.org
git+noreply at mindrot.org
Fri Nov 27 08:18:20 AEDT 2026
This is an automated email from the git hooks/post-receive script.
djm pushed a commit to branch master
in repository openssh.
commit 7a5192baa7caf9e651d2bb5dabec054efefb6cd6
Author: djm at openbsd.org <djm at openbsd.org>
AuthorDate: Thu Nov 26 19:18:53 2026 +0000
upstream: Don't let AddKeysToAgent clobber keys already in the
agent, potentially removing key constraints in the process.
Anthropic ANT-2026-VS3UR46N
OpenBSD-Commit-ID: 85dfbf645095f7d00e7c32126b483996e4c4b7d4
---
ssh_config.5 | 6 ++++--
sshconnect.c | 18 +++++++++++++++++-
2 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/ssh_config.5 b/ssh_config.5
index 08d238bc5..f07ecf68a 100644
--- a/ssh_config.5
+++ b/ssh_config.5
@@ -33,8 +33,8 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $OpenBSD: ssh_config.5,v 1.435 2026/10/30 08:42:29 djm Exp $
-.Dd $Mdocdate: October 30 2026 $
+.\" $OpenBSD: ssh_config.5,v 1.436 2026/11/26 19:18:53 djm Exp $
+.Dd $Mdocdate: November 26 2026 $
.Dt SSH_CONFIG 5
.Os
.Sh NAME
@@ -353,6 +353,8 @@ section of
to specify the key's lifetime in
.Xr ssh-agent 1 ,
after which it will automatically be removed.
+Keys that are already held by the agent are never replaced, so that any
+constraints they were added with remain in force.
The argument must be
.Cm no
(the default),
diff --git a/sshconnect.c b/sshconnect.c
index f3aa89da5..aafcf8662 100644
--- a/sshconnect.c
+++ b/sshconnect.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sshconnect.c,v 1.393 2026/10/30 08:39:48 djm Exp $ */
+/* $OpenBSD: sshconnect.c,v 1.394 2026/11/26 19:18:53 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo at cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo at cs.hut.fi>, Espoo, Finland
@@ -1918,6 +1918,22 @@ maybe_add_key_to_agent(const char *authfile, struct sshkey *private,
return;
}
+ /*
+ * Don't replace a key that the agent already holds: it may have been
+ * added with constraints (e.g. destination constraints that hide it
+ * from the connection bound to this session) that re-adding it here
+ * would discard.
+ */
+ r = ssh_agent_has_key(auth_sock, private);
+ if (r != SSH_ERR_KEY_NOT_FOUND && r != SSH_ERR_AGENT_NO_IDENTITIES) {
+ if (r == 0)
+ debug3("key already in agent, not adding");
+ else
+ debug3_r(r, "can't list agent keys, not adding key");
+ close(auth_sock);
+ return;
+ }
+
if (options.add_keys_to_agent == 2 &&
!ask_permission("Add key %s (%s) to agent?", authfile, comment)) {
debug3("user denied adding this key");
--
To stop receiving notification emails like this one, please contact
djm at mindrot.org.
More information about the openssh-commits
mailing list