2017-12-28 43 views
0

아파치 낙타 인터페이스도 AWS S3와 임시 보안,하지만 난 그것을 제대로 구축되지 않는 시나리오를 발견했다. 필자가 온라인에서 보았던 모든 Camel 예제를 살펴보면 비 로컬 환경에서 권장되는 업계 표준 AWS 임시 자격 증명을 사용하는 사람을 본 적이 없습니다. ~ 6 개월 동안 살아있는 정적 자격 증명을 사용하는 것은 보안 문제뿐만 아니라 수동 부담 (새로 고침)이며 현지 환경을 제외하고는 아무데도 사용하지 않아야합니다. 사용자 정의 감안할 때 아파치 낙타 AWS S3 : 자격 증명 만료 및

는, S3 클라이언트 설치, 낙타 임시 자격 증명을 취할 수 있지만, 낙타 경로가 어느 시점에 만료을 경험하게 될 것입니다 AWS S3 지적했다. Camel은 이것을 알기에 현명하지 않으며 예외 또는 시간 초과 오류를 무기한으로 던지지 않고 S3 버킷을 폴링하려고 시도합니다.

나는 그렇게처럼 내 엔드 포인트에 시간 제한 설정을 추가하는 것을 시도했다 :

aws-s3://" + incomingAWSBucket + "?" + "amazonS3Client=#amazonS3Client&timeout=4000 

사람이 AWS 임시 보안과 낙타 인터페이스 또는 AWS 자격 증명이 만료 경우 (상기 설정 주어진) 예외를 throw하는 방법을 설명 할 수 ?

도움 주셔서 감사합니다. 다른 사람이 그것을 원하는 경우

+0

당신은 낙타 버전이 사용합니까, 더 말해, 수 그 경로에서 끝점을 사용합니까? 또는 무엇을합니까? 그리고 만료 된 자격 증명의 경우 수행하려는 작업 –

+0

Camel 버전 2.20.0, AWS s3을 가리키는 하나의 경로가 있고 "to"경로가 로컬 디렉토리입니다. 마지막으로, 자격 증명이 더 이상 작동하지 않으면 (기본적으로 시간 초과 예외) 낙타에 예외를 던지 려합니다. –

+0

아직 증명할 필요는 없지만 낙타 프로세스 내에서 AWS의 기본 자격 증명 체인에 의존하는 맞춤 S3 클라이언트를 사용하면 자격 증명 자체를 관리하는 클라이언트가 생성되는 것 같습니다. 실험을 마칠 때 이것을 업데이트 할 것입니다 : AmazonS3ClientBuilder.standard(). withRegion (Regions.US_WEST_2) .build(); –

답변

0

이 질문에 대한 대답은 튜토리얼에 대한 충분한 밀도이다. 지금은 적절한 포럼과 스레드에 복사하여 붙여 넣어 단어를 알아냅니다.

불평하지 않고, 나는 카멜이 얼마나 강력한 지, 설명서 및 예제 기반이 무엇인지 말할 수 있습니다. 정말 AWS의 세계에서 생산 시나리오 부족 ... 한숨은 ...는 오픈 소스 LIB의 입 아마 스트레칭을 이잖아.

camel-s3 documentation 공식을 참조하여 자격 증명 문제를 해결하는 방법을 알아 냈습니다. 고급 S3 구성을 만드는 방법을 먼저 보도록하겠습니다. (aws sdk 자체에 의존합니다. s3 클라이언트를 수동으로). 나는이 알아 낸 후 , 나는 내가 클라이언트 자체를 구축 할 수 있어요 때문에 이것이 EC2 인스턴스에서 일할 수있는 방법을 알아 내기 위해 aws sdk documentation on IAM credentials에게 갔다. 앞서 언급 한 문서에는 몇 가지 베어 본 예제가 있습니다. 나열된 예제로 테스트를 테스트하자마자 자격 증명 새로 고침 (이 질문의 유일한 목적)이 작동하지 않는 것으로 나타났습니다. 처음에는 자격 증명을 얻을 수 있었지만 수동으로 만료 된 후에는 테스트 중에 다시 채워지지 않았습니다. 마지막으로 자격 증명의 새로 고침을 처리 할 수있는 공급자 체인을 지정할 수 있다고 생각했습니다. 이것을 설명하는 aws 문서는 here입니다.

결국 aws s3 버킷을 폴링하는 내 로컬 낙타 설정에 대한 정적 자격 증명이 필요하지만 ec2s에 살고있는 원격 환경은 스스로를 완벽하게 새로 고치는 임시 자격 증명으로 액세스 할 수 있습니다. 와우 사! :)

이 작업을 수행하려면, 난 그저 내 로컬 개발 및 임시 IAM 자격 증명에 의존하는 원격 낙타 설정에 로컬 낙타 설정을 사용하는 공장을 만들었다. 이렇게하면 보안 우려와 모든 원격 환경에 대한 자격 증명을 수동으로 새로 고쳐야하는 작업을 줄일 수 있습니다!

팩토리를 만드는 방법이나 내 로컬 & 원격 구성이 어떻게 설정되었는지는 설명하지 않지만 원격 설정을 위해 S3 클라이언트를 만드는 AmazonS3ClientBuilder의 코드 샘플을 포함합니다.

AmazonS3ClientBuilder.standard() 
    .withCredentials(new InstanceProfileCredentialsProvider(false)) 
    .withRegion(Regions.US_WEST_2) 
    .build(); 

내가 어떻게 작동하는지 알고 싶다면 전체 프로세스를 보여주는 예제 프로젝트를 제공 할 수 있습니다. 요청에 의해

, 여기 S3 클라이언트 내 로컬 및 원격 구현은 다음과 같습니다 지역 :

public class LocalAWSS3ClientManagerImpl implements AWSS3ClientManager { 
    private static Logger logger = LoggerFactory.getLogger(LocalAWSS3ClientManagerImpl.class); 
    private PriorityCodeSourcesRoutesProperties priorityCodeSourcesRoutesProperties; 
    private SimpleRegistry registry = new SimpleRegistry(); 
    private CamelContext camelContext; 

public LocalAWSS3ClientManagerImpl(PriorityCodeSourcesRoutesProperties priorityCodeSourcesRoutesProperties) { 
    this.priorityCodeSourcesRoutesProperties = priorityCodeSourcesRoutesProperties; 
    registry.put("amazonS3Client", getS3Client()); 
    camelContext = new DefaultCamelContext(registry); 
    logger.info("Creating an AWS S3 manager for a local instance (you should not see this on AWS EC2s)."); 
} 

private AmazonS3 getS3Client() { 
    try { 
     String awsBucketAccessKey = priorityCodeSourcesRoutesProperties.getAwsBucketAccessKey(); 
     String awsBucketSecretKey = priorityCodeSourcesRoutesProperties.getAwsBucketSecretKey(); 
     AWSCredentials awsCredentials = new BasicAWSCredentials(awsBucketAccessKey, awsBucketSecretKey); 
     return AmazonS3ClientBuilder.standard().withCredentials(
       new AWSStaticCredentialsProvider(awsCredentials)).build(); 
    } catch (RuntimeException ex) { 
     logger.error("Could not create AWS S3 client with the given credentials from the local config."); 
    } 
    return null; 
} 

public Endpoint getIncomingAWSEndpoint(final String incomingAWSBucket, final String region, 
     final String fileNameToSaveAndDownload) { 
    return camelContext.getEndpoint(
      "aws-s3://" + incomingAWSBucket + "?" + "amazonS3Client=#amazonS3Client" 
      + "&region=" + region + "&deleteAfterRead=false" + "&prefix=" + fileNameToSaveAndDownload); 
} 

public Endpoint getOutgoingLocalEndpoint(final String outgoingEndpointDirectory, 
     final String fileNameToSaveAndDownload) { 
    return camelContext.getEndpoint(
      "file://" + outgoingEndpointDirectory + "?" + "fileName=" 
      + fileNameToSaveAndDownload + "&readLock=markerFile"); 
} 
} 

원격 :

public class RemoteAWSS3ClientManagerImpl implements AWSS3ClientManager { 
private static Logger logger = LoggerFactory.getLogger(RemoteAWSS3ClientManagerImpl.class); 
private PriorityCodeSourcesRoutesProperties priorityCodeSourcesRoutesProperties; 
private SimpleRegistry registry = new SimpleRegistry(); 
private CamelContext camelContext; 

public RemoteAWSS3ClientManagerImpl(PriorityCodeSourcesRoutesProperties priorityCodeSourcesRoutesProperties) { 
    this.priorityCodeSourcesRoutesProperties = priorityCodeSourcesRoutesProperties; 
    registry.put("amazonS3Client", getS3Client()); 
    camelContext = new DefaultCamelContext(registry); 
    logger.info("Creating an AWS S3 client for a remote instance (normal for ec2s)."); 
} 

private AmazonS3 getS3Client() { 
    try { 
     logger.info("Attempting to create an AWS S3 client with IAM role's temporary credentials."); 
     return AmazonS3ClientBuilder.standard() 
            .withCredentials(new InstanceProfileCredentialsProvider(false)) 
            .withRegion(Regions.US_WEST_2) 
            .build(); 
    } catch (RuntimeException ex) { 
     logger.error("Could not create AWS S3 client with the given credentials from the instance. " 
        + "The default credential chain was used to create the AWS S3 client. " 
        + ex.toString()); 
    } 
    return null; 
} 

public Endpoint getIncomingAWSEndpoint(final String incomingAWSBucket, final String region, 
     final String fileNameToSaveAndDownload) { 
    return camelContext.getEndpoint(
      "aws-s3://" + incomingAWSBucket + "?" + "amazonS3Client=#amazonS3Client" 
      + "&region=" + region + "&deleteAfterRead=false" + "&prefix=" + fileNameToSaveAndDownload); 
} 

public Endpoint getOutgoingLocalEndpoint(final String outgoingEndpointDirectory, 
     final String fileNameToSaveAndDownload) { 
    return camelContext.getEndpoint(
      "file://" + outgoingEndpointDirectory + "?" + "fileName=" 
      + fileNameToSaveAndDownload + "&readLock=markerFile"); 
} 

} 
+0

이것은 정말로 흥미 롭습니다. Camel 2.21.x에서 클라이언트 구성을 약간 변경했습니다. https://github.com/apache/camel/commit/60d0ed8b43c0860ab42abb436df05f5c7a5a9e25 예제 프로젝트를 가르쳐 주시겠습니까? – Oscerd

+0

나는 하나를 만들 수 있지만, 절대적으로 필요한 경우가 아니라면 오히려하지 않을 것이다. 이번 주에 시간을 갖게되면 원격 클라이언트와 로컬 클라이언트를 어떻게 조합하는지에 대한 아이디어를 더주기 위해 전체 클래스를 추가 할 것입니다. –

+0

당신이 보낸 커밋에 관해서는, 이것이 어떻게 기능을 크게 확장시키는 지 보지 못합니다. 정적 자격 증명 (여전히 좋은 기본 동작)에 의존하지만 코드가 필요할 경우 두 시나리오 (원격 및 로컬)를 올바르게 처리하도록 수정할 수 있습니다. –