New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Java Storage NIO: FileSystemProvider::checkAccess fails on '/' with StorageException #1062
Comments
Note:
|
Hi @nielsbasjes, Thanks for filing the issue. I've been able to replicate your findings and add a new test to the test suite. Unfortunately, I don't yet have a fix I can post. I do have a workaround which might be able to tide you over until I can get a fix. Initial Investigation FindingsThe error appears to be partially happening in the path parser logic and how it gets translated to the actual call to GCS. In this case having the trailing slash -- or solo slash -- the parser thinks there is an object part to the URI, but there isn't when it comes time to query GCS which fails to receive an object id. WorkaroundIn this case if you remove the trailing slash, the method is able to complete without exception.
BackgroundGCS doesn't actually have directories, so all directory specific operations in this library are either emulated, or optimistically lie. So in the case of asking the files system if write access is enabled for a directory |
Hi, This fixes the root issue and also has a quick fix for being able to get the attributes. This also includes a hack to provide a faked set of posix attributes because apparently many libraries assume the entire world is a posix world Let me know what you think. |
Note that with the fixes I wrote I can now simply tell the Apache Mina SFTP server to use a |
Some additional info to help you verify what I created. With an ssh agent running with my key and my authorized_keys also having my public key; public class CloudStorageSftp {
private static final Logger LOG = LoggerFactory.getLogger(CloudStorageSftp.class);
public static void main(String[] args) throws IOException, InterruptedException {
if (args.length == 0) {
LOG.error("Must specify the bucket to connect to.");
return;
}
String bucketName = args[0];
try(SshServer server = SshServer.setUpDefaultServer()) {
server.setPort(2222);
server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("my.pem").toPath()));
SftpSubsystemFactory sftpSubsystemFactory = new SftpSubsystemFactory();
sftpSubsystemFactory.setFileSystemAccessor(SftpFileSystemAccessor.DEFAULT);
server.setSubsystemFactories(Collections.singletonList(sftpSubsystemFactory));
server.setFileSystemFactory(new FileSystemFactory() {
@Override
public Path getUserHomeDir(SessionContext session) {
return Path.of("/");
}
@Override
public FileSystem createFileSystem(SessionContext session) {
return FileSystems.getFileSystem(URI.create("gs://" + bucketName));
}
});
server.start();
// Only for testing, 10000 seconds is fine.
sleep(10000000L);
}
}
} |
@BenWhitehead is there something I can do to get to a fixed implementation? |
Apologies for the delay. I think the changes you've made in your branch in general make sense. Would you be willing to open a PR to this repo for inclusion? If you are willing, I think the smoothest path to merging things would be to break into 3 PRs each with commensurate tests:
I believe 1 and 2 above could be opened and reviewed at the same time, while 3 would depend on 2. |
Yes, I'll get on it.
|
Great, thanks ahead of time for the contribution! Once you open your first PR our CLA bot will reply with instructions. If you want to write a test that hits the actual service, feel free to add to ITGcsNio. It will be picked up and run in our integration tests environment with access to the production service. To run the integration suite locally, you'll need some form of credentials (either Application Default Credentials via |
@BenWhitehead can you please approve me running the workflows? Thanks. |
With the 3 patches I have submitted combined and used in the minimal SFTP server I posted earlier I now see this when I list the files in my test cloud storage instance.
This is for me a totally acceptable answer. |
For easier testing: https://github.com/nielsbasjes/MinimalSftpCloudStorage |
…1065) Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [x] Make sure to open an issue: https://togithub.com/googleapis/java-storage-nio/issues/1062 - [x] Ensure the tests and linter pass - [x] Code coverage does not decrease (if any source code was changed) - [x] Appropriate docs were updated (if necessary) Fixes #1062 ☕️
A v0.125.0 was cut a couple days ago with the first two PRs. I'll cut another release early next week to include the final one. |
v0.126.0 has been cut with POSIX emulation |
Awesome. Thanks for all your help. |
Using com.google.cloud:google-cloud-nio:0.124.20 the CloudStorageFileSystemProvider implementation of FileSystemProvider.checkAccess fails when asking about the root directory.
Take this code fragment and fill in a cloud storage bucket name you have access to:
Stack trace
NOTE: I have hidden the real bucket name.
External references such as API reference guides
Any additional information below
I ran into this problem when "simply" trying to attach Apache Mina SFTP to a Google Cloud Bucket.
Note that this all does work as expected on
Only on '/' it fails.
The text was updated successfully, but these errors were encountered: