Flink SecurityContext 概览
在Flink中通过SecurityContext进行操作的权限验证,验证通过以后执行具体操作。接口中定义的一个方法如下:
<T> T runSecured(Callable<T> securedCallable) throws Exception;
Flink中在ClusterEntrypoint类中通过installSecurityContext进行安全上下文的组装,Flink默认是NoOpSecurityContext鉴权方式,不需要鉴权,直接进行对应的方法。
同时还支持HadoopModule、JaasModele、ZookeeperModule等方式的认证方式。
1 public static void install(SecurityConfiguration config) throws Exception { 2 3 // install the security modules 4 List<SecurityModule> modules = new ArrayList<>(); 5 try { 6 for (SecurityModuleFactory moduleFactory : config.getSecurityModuleFactories()) { 7 SecurityModule module = moduleFactory.createModule(config); 8 // can be null if a SecurityModule is not supported in the current environment 9 if (module != null) { 10 module.install(); 11 modules.add(module); 12 } 13 } 14 } 15 catch (Exception ex) { 16 throw new Exception("unable to establish the security context", ex); 17 } 18 installedModules = modules; 19 20 // First check if we have Hadoop in the ClassPath. If not, we simply don't do anything. 21 try { 22 Class.forName( 23 "org.apache.hadoop.security.UserGroupInformation", 24 false, 25 SecurityUtils.class.getClassLoader()); 26 27 // install a security context 28 // use the Hadoop login user as the subject of the installed security context 29 if (!(installedContext instanceof NoOpSecurityContext)) { 30 LOG.warn("overriding previous security context"); 31 } 32 UserGroupInformation loginUser = UserGroupInformation.getLoginUser(); 33 installedContext = new HadoopSecurityContext(loginUser); 34 } catch (ClassNotFoundException e) { 35 LOG.info("Cannot install HadoopSecurityContext because Hadoop cannot be found in the Classpath."); 36 } catch (LinkageError e) { 37 LOG.error("Cannot install HadoopSecurityContext.", e); 38 } 39 }
第6行,getSecurityModuleFactories就是默认的
Arrays.asList(new HadoopModuleFactory(), new JaasModuleFactory(), new ZookeeperModuleFactory())
这三类Factory,在对应的Factory中生成与之想对应的Modele。
从21行开始,还是对hadoop的特殊操作,直接在环境变量中加载hadoop的安全验证组件UserGroupInformation,如果环境变量中存在,那么获取hadoop中的用户信息构造HadoopSecurityContext,并且更新installedContext。

浙公网安备 33010602011771号