当前位置: 首页 > news >正文

网站建设需要怎么维护做足彩推荐赚钱的网站

网站建设需要怎么维护,做足彩推荐赚钱的网站,建筑网站管桩进场验收规范,手机广告设计软件Vault 是由 HashiCorp 开发的一款用于管理和保护敏感数据的工具。它可以帮助组织安全地存储、分发和使用各种类型的敏感信息,如 API 密钥、密码、证书等。 应用场景 1、API 密钥管理: 将 API 密钥存储在 Vault 中,并根据需要分配给不同的服…

Vault 是由 HashiCorp 开发的一款用于管理和保护敏感数据的工具。它可以帮助组织安全地存储、分发和使用各种类型的敏感信息,如 API 密钥、密码、证书等。

应用场景

1、API 密钥管理:
将 API 密钥存储在 Vault 中,并根据需要分配给不同的服务或团队成员。这样可以确保密钥的安全性和可追溯性。
2、数据库凭证管理:
Vault 可以生成动态数据库凭证,每个凭证都有特定的权限和有效期。当凭证不再需要时,可以自动撤销。
3、SSH 密钥管理:
Vault 可以作为 SSH 密钥管理系统,为用户提供一次性或长期有效的 SSH 密钥。
4、TLS/SSL 证书管理:
Vault 可以签发和管理 TLS/SSL 证书,简化证书生命周期管理过程。
5、云平台凭证管理:
Vault 可以管理和轮换 AWS、Azure、Google Cloud Platform 等云平台的凭证。
6、CI/CD 环境中的秘密管理:
在持续集成/持续交付管道中使用 Vault 来传递敏感信息,如 Docker 镜像仓库凭证、配置文件等。
7、微服务架构中的秘密管理:
在微服务架构中,不同服务之间可能需要共享某些敏感信息。Vault 可以集中管理这些信息,并根据服务的需求提供相应的访问权限。
8、合规性和审计:
Vault 提供强大的审计功能,帮助组织满足合规要求,如 GDPR、HIPAA 等。

启动Vault并配置Token

首先,确保你已经安装并启动了Vault服务器。你可以使用以下命令来初始化和启动Vault:

# 启动Vault开发服务器
vault server -dev# 记录下生成的root token和unseal key

我的Vault根Token是 s.9ZvP3oJHqQcXzKw6FyGmEhLr,并且Vault运行在默认的 http://localhost:8200 上。

将敏感信息存储到Vault

使用Vault CLI或API将敏感信息存储到Vault中。这里我们使用Vault CLI来创建一个密钥路径 secret/app-secrets 并添加一个键值对 {“password”: “mySuperSecretPassword”}。

# 设置Vault地址
export VAULT_ADDR=http://localhost:8200# 设置Vault Token
export VAULT_TOKEN=s.9ZvP3oJHqQcXzKw6FyGmEhLr# 写入敏感信息到Vault
vault kv put secret/app-secrets password=mySuperSecretPassword

代码实操

<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-vault-config</artifactId></dependency><dependency><groupId>org.springframework.security</groupId><artifactId>spring-security-core</artifactId></dependency><dependency><groupId>org.springframework.security</groupId><artifactId>spring-security-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency>
</dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency></dependencies>
</dependencyManagement><properties><java.version>17</java.version><spring-cloud.version>2022.0.1</spring-cloud.version>
</properties>

配置Vault (application.yml)

server:port:8080spring:
cloud:vault:host:localhostport:8200scheme:httptoken:s.9ZvP3oJHqQcXzKw6FyGmEhLrgeneric:enabled:truebackend:secretdefault-context:app-secrets

创建Vault认证类 (VaultConfig.java)

package com.example.vaultdemo.config;import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.vault.authentication.ClientAuthentication;
import org.springframework.vault.authentication.TokenAuthentication;
import org.springframework.vault.client.VaultEndpoint;
import org.springframework.vault.core.VaultTemplate;@Configuration
publicclass VaultConfig {@Beanpublic ClientAuthentication clientAuthentication() {returnnew TokenAuthentication("s.9ZvP3oJHqQcXzKw6FyGmEhLr");}@Beanpublic VaultTemplate vaultTemplate(ClientAuthentication clientAuthentication) {VaultTemplate vaultTemplate = new VaultTemplate(VaultEndpoint.create("localhost", 8200), clientAuthentication);return vaultTemplate;}
}

编写服务类 (SecretService.java)

package com.example.vaultdemo.service;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.vault.core.VaultOperations;@Service
publicclass SecretService {privatefinal VaultOperations vaultOperations;@Autowiredpublic SecretService(VaultOperations vaultOperations) {this.vaultOperations = vaultOperations;}public String getSecretPassword() {return vaultOperations.read("secret/app-secrets").getData().get("data").toString();}
}

配置Spring Security (WebSecurityConfig.java)

package com.example.vaultdemo.config;import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;@Configuration
@EnableWebSecurity
publicclass WebSecurityConfig extends WebSecurityConfigurerAdapter {@Overrideprotected void configure(HttpSecurity http) throws Exception {http.authorizeRequests().antMatchers("/secrets/**").hasRole("ADMIN").anyRequest().authenticated().and().httpBasic();}@Bean@Overridepublic UserDetailsService userDetailsService() {UserDetails admin = User.withDefaultPasswordEncoder().username("admin").password("password").roles("ADMIN").build();UserDetails user = User.withDefaultPasswordEncoder().username("user").password("password").roles("USER").build();returnnew InMemoryUserDetailsManager(admin, user);}
}

编写控制器 (SecretController.java)

package com.example.vaultdemo.controller;import com.example.vaultdemo.service.SecretService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
@RequestMapping("/secrets")
publicclass SecretController {privatefinal SecretService secretService;@Autowiredpublic SecretController(SecretService secretService) {this.secretService = secretService;}@GetMapping("/password")public ResponseEntity<String> getPassword() {String password = secretService.getSecretPassword();return ResponseEntity.ok(password);}
}

主应用程序类 (VaultDemoApplication.java)

package com.example.vaultdemo;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class VaultDemoApplication {public static void main(String[] args) {SpringApplication.run(VaultDemoApplication.class, args);}
}

测试用例 (SecretServiceTest.java)

package com.example.vaultdemo;import com.example.vaultdemo.service.SecretService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;importstatic org.assertj.core.api.Assertions.assertThat;@SpringBootTest
class SecretServiceTest {@Autowiredprivate SecretService secretService;@Testvoid shouldReturnCorrectPassword() {// 在Vault中的路径为secret/data/app-secrets,键值对为{"password": "mySuperSecretPassword"}assertThat(secretService.getSecretPassword()).contains("mySuperSecretPassword");}
}

启动Spring Boot应用程序
确保所有文件都已正确放置在相应的目录中,然后运行Spring Boot应用程序。

测试API
使用Postman发送HTTP GET请求到 http://localhost:8080/secrets/password,

使用HTTP Basic Authentication,用户名为 admin,密码为 password。

请求

URL: http://localhost:8080/secrets/password
Method: GET
Authorization:
Type: Basic Auth
Username: admin
Password: password

响应

{"password": "mySuperSecretPassword"
}
http://www.dtcms.com/a/526765.html

相关文章:

  • 最新网站建设进程陆金所 网站开发二部
  • 给网站做app哈尔滨市建设工程信息
  • 手机网站制作视频教程媒体查询做响应式网站
  • 工业设计网站有那些wordpress站内信插件
  • wordpress如何做网站怎样建网站赚钱
  • 为女友做网站wordpress源代码如何在本地编辑
  • 重庆市建筑工程造价信息网官网郑州seo优化外包热狗网
  • 网站底部图标一个主体如何添加网站
  • 饿了么企业网站公司注册地址多少钱
  • 做外贸网站空间多少g在线建站软件
  • 重庆专业网站开发服务WordPress百度智能小程序
  • 外包干了9天,技术退步明显。。。。。
  • 中英文网站建设公司网站登录按钮点击没反应什么原因
  • 老生常谈的字符串拼接
  • 深圳制作企业网站的公司库存管理软件免费版
  • 潍坊市建设厅网站苏州市建设工程建设中心网站
  • 蓝海国际版网站建设专业做物业网站的公司
  • 为了加强公司网站建设甘肃省建设厅注册中心网站首页
  • 国际网站开发客户网站建设 乐视
  • 高新技术企业网站怎么做做网站绿色和什么颜色搭配
  • wap门户网站网站开发 源码
  • 视频网站顶部效果怎么做的内蒙古自治区住房和城乡建设部网站
  • 做网站用什么配置的笔记本怎么做微信网页制作
  • 什么专业学做网站把自己做的网站进行app封包
  • 制作网站费用号卡分销系统
  • 政务建设网站得必要性旅游网站开发背景及意义
  • 微信免费做邀请函模版网站如何建设高校网站
  • 网站开发费怎么做会计分录免费永久vps服务器
  • 建立平台网站要多久电脑中怎样安装wordpress
  • 多态(1),咕咕咕!