为什么 Artifactory 在每次 npm 安装请求时都对用户进行身份验证?
Why does Artifactory authenticate user on every npm install request?
我们使用 Artifactory 来存储本地 npm 工件并缓存远程 npm 注册表。
要使用 npm 对 Artifactory 进行身份验证(使用 AD 帐户),我们使用 Artifactory 的 "Set Me Up" 页面建议的基本身份验证。例如:
_auth = < username >:< password >
email = youremail@email.com
always-auth = true
一切正常,但存在一个问题,即 Artifactory 对下载的每个包的用户进行身份验证。 artifactory.log 日志看起来像这样(请注意,输出已编辑):
Trying to authenticate user 'user1' via ldap.
Attempting to bind as cn=user1,ou=someou,ou=ou1,ou=ou2,ou=ou3,dc=internal,dc=comp,dc=int
Retrieving attributes...
'user1' authenticated successfully by ldap server.
Loading LDAP groups
Finished Loading LDAP groups
Trying to authenticate user 'user1' via ldap.
Trying to authenticate user 'user1' via ldap.
Trying to authenticate user 'user1' via ldap.
Trying to authenticate user 'user1' via ldap.
Trying to authenticate user 'user1' via ldap.
Trying to authenticate user 'user1' via ldap.
Trying to authenticate user 'user1' via ldap.
Trying to authenticate user 'user1' via ldap.
Trying to authenticate user 'user1' via ldap.
Trying to authenticate user 'user1' via ldap.
Trying to authenticate user 'user1' via ldap.
Attempting to bind as cn=user1,ou=someou,ou=ou1,ou=ou2,ou=ou3,dc=internal,dc=comp,dc=int
...
正如我所提到的,身份验证有效并且工件也被下载但是这种针对每个工件的持续身份验证有时会导致 LDAP 服务器超时:
Failed to authenticate user 'user1' using ldap.
org.springframework.ldap.UncategorizedLdapException: Uncategorized exception occured during LDAP processing; nested exception is javax.naming.NamingException: LDAP response read timed out, timeout used:10000ms.
at org.springframework.ldap.support.LdapUtils.convertLdapException(LdapUtils.java:217)
at org.springframework.ldap.core.support.AbstractContextSource.createContext(AbstractContextSource.java:285)
at org.springframework.ldap.core.support.AbstractContextSource.doGetContext(AbstractContextSource.java:119)
at org.springframework.ldap.core.support.AbstractContextSource.getReadOnlyContext(AbstractContextSource.java:138)
at org.springframework.ldap.core.LdapTemplate.executeReadOnly(LdapTemplate.java:791)
...
这会导致当时正在下载的工件无法下载,从而导致我们的构建失败。
所以,我的问题是为什么会发生这种情况,有没有办法避免这种情况,因为每次我们 运行 构建作业时它也会给我们的 LDAP 服务器增加负载?
由于对包的每个请求都是一个单独的请求,而不是可以识别的一个长事务的一部分,因此 Artifactory 必须对用户进行身份验证。考虑一个场景,如果同一用户从多个主机发送请求,您如何确保它具有正确的凭据?
话虽如此,Artifactory 有一个缓存机制来缓存有关针对外部系统的身份验证的数据,例如 LDAP for REST API 请求。您可以通过设置 artifactory.security.authentication.cache.idleTimeSecs
Artifactory 系统 属性.
来调整此缓存以减少发送到 LDAP 服务器的请求量
更多信息,请查看Managing Security with LDAP
我们使用 Artifactory 来存储本地 npm 工件并缓存远程 npm 注册表。 要使用 npm 对 Artifactory 进行身份验证(使用 AD 帐户),我们使用 Artifactory 的 "Set Me Up" 页面建议的基本身份验证。例如:
_auth = < username >:< password >
email = youremail@email.com
always-auth = true
一切正常,但存在一个问题,即 Artifactory 对下载的每个包的用户进行身份验证。 artifactory.log 日志看起来像这样(请注意,输出已编辑):
Trying to authenticate user 'user1' via ldap.
Attempting to bind as cn=user1,ou=someou,ou=ou1,ou=ou2,ou=ou3,dc=internal,dc=comp,dc=int
Retrieving attributes...
'user1' authenticated successfully by ldap server.
Loading LDAP groups
Finished Loading LDAP groups
Trying to authenticate user 'user1' via ldap.
Trying to authenticate user 'user1' via ldap.
Trying to authenticate user 'user1' via ldap.
Trying to authenticate user 'user1' via ldap.
Trying to authenticate user 'user1' via ldap.
Trying to authenticate user 'user1' via ldap.
Trying to authenticate user 'user1' via ldap.
Trying to authenticate user 'user1' via ldap.
Trying to authenticate user 'user1' via ldap.
Trying to authenticate user 'user1' via ldap.
Trying to authenticate user 'user1' via ldap.
Attempting to bind as cn=user1,ou=someou,ou=ou1,ou=ou2,ou=ou3,dc=internal,dc=comp,dc=int
...
正如我所提到的,身份验证有效并且工件也被下载但是这种针对每个工件的持续身份验证有时会导致 LDAP 服务器超时:
Failed to authenticate user 'user1' using ldap.
org.springframework.ldap.UncategorizedLdapException: Uncategorized exception occured during LDAP processing; nested exception is javax.naming.NamingException: LDAP response read timed out, timeout used:10000ms.
at org.springframework.ldap.support.LdapUtils.convertLdapException(LdapUtils.java:217)
at org.springframework.ldap.core.support.AbstractContextSource.createContext(AbstractContextSource.java:285)
at org.springframework.ldap.core.support.AbstractContextSource.doGetContext(AbstractContextSource.java:119)
at org.springframework.ldap.core.support.AbstractContextSource.getReadOnlyContext(AbstractContextSource.java:138)
at org.springframework.ldap.core.LdapTemplate.executeReadOnly(LdapTemplate.java:791)
...
这会导致当时正在下载的工件无法下载,从而导致我们的构建失败。
所以,我的问题是为什么会发生这种情况,有没有办法避免这种情况,因为每次我们 运行 构建作业时它也会给我们的 LDAP 服务器增加负载?
由于对包的每个请求都是一个单独的请求,而不是可以识别的一个长事务的一部分,因此 Artifactory 必须对用户进行身份验证。考虑一个场景,如果同一用户从多个主机发送请求,您如何确保它具有正确的凭据?
话虽如此,Artifactory 有一个缓存机制来缓存有关针对外部系统的身份验证的数据,例如 LDAP for REST API 请求。您可以通过设置 artifactory.security.authentication.cache.idleTimeSecs
Artifactory 系统 属性.
来调整此缓存以减少发送到 LDAP 服务器的请求量
更多信息,请查看Managing Security with LDAP