华润大学ldap账号是什么_认证配置 - 接入 LDAP / AD 域账号(Beta) - 《KubeSphere v2.1 使用手册》 - 书栈网 · BookStack...

接入 LDAP / AD 域账号(Beta)

如果您的企业使用 LDAP 作为用户认证系统,您可以在 KubeSphere 中通过脚本配置内置的 OpenLDAP 接入您的 LDAP 用户系统,从而允许用户使用他们的 LDAP 账号来登录 KubeSphere 控制台。

以下将说明 KubeSphere 如何接入 AD 域账号,同样适用于对接外部 LDAP。

说明:本方法将通过后台脚本接入,3.0 版本将支持在 UI 通过更简单的配置方式来接入 LDAP / AD 域账号。

查看 AD 域

在 windows server 2016 上,进入 Active Director 管理中心,获取 managerDN (可以是只读账号)

创建并编辑脚本

登陆 KubeSphere 后台节点,创建一个 inject-ks-account.sh 的脚本,然后修改脚本中 host、managerDN、managerPWD、userSearchBase 这四个配置为您 AD 域实际的参数:

#!/bin/bash

set-e

host="139.198.111.111:30222"# 将 host 的值改为实际的服务器 IP 与 端口

managerDN="cn=Administrator,cn=Users,dc=kubesphere,dc=com"# 值修改为实际的 AD 域的管理账号, 可以为只读账号

managerPWD="123456789"# 管理账号密码

userSearchBase="cn=Users,dc=kubesphere,dc=com"# 根据实际配置进行修改

sidecar="kubespheredev/ad-sidecar:v0.0.1"

generate_config(){

cat<

apiVersion:v1

data:

sync.yaml:|

sync:

interval:"300s"

src:

host:"${host}"

managerDN:"${managerDN}"

managerPWD:"${managerPWD}"

userSearchBase:"${userSearchBase}"

usernameAttribute:"sAMAccountName"

descriptionAttribute:"description"

mailAttribute:"mail"

dst:

host:"openldap.kubesphere-system.svc:389"

managerDN:"cn=admin,dc=kubesphere,dc=io"

managerPWD:"admin"

userSearchBase:"ou=Users,dc=kubesphere,dc=io"

kind:ConfigMap

metadata:

name:ad-sync-config

namespace:kubesphere-system

EOF

}

# apply sync config

generate_config|kubectl apply-f-

# inject sidecar

kubectl-n kubesphere-systemgetdeploy ks-account-o json|jq'.spec.template.spec.volumes += [{"configMap":{"name":"ad-sync-config"},"name":"ad-sync-config"}]'|jq'.spec.template.spec.containers += [{"command":["ad-sidecar","--logtostderr=true","--v=2"],"image":"'${sidecar}'","imagePullPolicy":"IfNotPresent","name":"ad-sidecar","ports":[{"containerPort":19090,"protocol":"TCP"}],"volumeMounts":[{"mountPath":"/etc/kubesphere/sync.yaml","name":"ad-sync-config","subPath":"sync.yaml"}]}]'|kubectl apply-f-

# use proxy port

kubectl-n kubesphere-systemgetsvc ks-account-o json|jq'.spec.ports[0].targetPort=19090'|kubectl apply-f-

执行脚本并验证账号接入

创建完成后,后台执行 inject-ks-account.sh

该脚本会重启 ks-account 的 Pod,会有短暂几分钟账号无法登陆。待 ks-account 的 pod 就绪后, 登录 KubeSphere 可以看到 AD 中的账户数据:

接入的账号默认无任何权限,需要在平台的用户管理页面给接入的用户授予角色。当接入的账号授予集群角色后,即可用 AD 域中的账户登录 KubeSphere。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用AD账号进行认证登陆,可以使用Spring Security框架来实现。Spring Security是一个强大的安全框架,可以帮助我们实现身份验证、授权、会话管理、攻击防范等方面的功能。 首先,需要在Spring Boot项目中添加Spring Security依赖。在pom.xml文件中添加如下依赖: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> ``` 接下来,需要配置Spring Security。在配置文件中添加以下配置: ```yaml spring: security: ldap: url: ldap://ad.example.com:389/dc=example,dc=com user-search-base: ou=users,dc=example,dc=com user-search-filter: (sAMAccountName={0}) ``` 这里的配置使用的是LDAP协议进行认证,需要提供AD的连接信息和用户信息查询条件。 然后,在Spring Boot项目中创建一个自定义的UserDetailsService实现类,用于从AD中查询用户信息,并将其封装为Spring Security的UserDetails对象返回。如下所示: ```java @Service public class CustomUserDetailsService implements UserDetailsService { @Autowired private LdapTemplate ldapTemplate; @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { AndFilter filter = new AndFilter(); filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("sAMAccountName", username)); List<User> users = ldapTemplate.search("", filter.encode(), new UserAttributesMapper()); if (users.size() != 1) { throw new UsernameNotFoundException("User not found"); } return users.get(0); } private class UserAttributesMapper implements AttributesMapper<User> { @Override public User mapFromAttributes(Attributes attributes) throws NamingException { String username = (String) attributes.get("sAMAccountName").get(); String password = "dummy"; List<GrantedAuthority> authorities = new ArrayList<>(); authorities.add(new SimpleGrantedAuthority("ROLE_USER")); return new User(username, password, authorities); } } } ``` 这里使用LdapTemplate查询AD中的用户信息,将其封装为Spring Security的UserDetails对象返回。需要注意的是,这里为了简化,将密码设置为了固定值,实际使用中应该从AD中获取密码。 最后,在Spring Security的配置类中添加如下配置: ```java @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired private CustomUserDetailsService userDetailsService; @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .anyRequest().authenticated() .and() .formLogin() .loginPage("/login") .permitAll() .and() .logout() .permitAll(); } @Override public void configure(AuthenticationManagerBuilder auth) throws Exception { auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder()); } @Bean public PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } } ``` 这里的配置包括了身份验证和授权的相关配置,其中使用了自定义的UserDetailsService实现类进行身份验证。需要注意的是,这里使用了BCryptPasswordEncoder对密码进行加密,实际使用中应该根据具体的情况选择合适的加密算法。 完成以上配置后,就可以使用AD账号进行认证登陆了。在原有的登陆系统中,在登陆页面中添加一个链接或按钮,跳转到Spring Boot项目中的登陆页面即可。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值