Skip to content
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

fix: create the metastore backups directory if it does not exist #5879

Merged
merged 1 commit into from
Jul 24, 2020

Conversation

spena
Copy link
Member

@spena spena commented Jul 24, 2020

Description

Creates the KSQL metastore backups directory if it does not exist. It also checks the existing directory is readable and writeable.

Testing done

Unit tests

Reviewer checklist

  • Ensure docs are updated if necessary. (eg. if a user visible feature is being added or changed).
  • Ensure relevant issues are linked (description should include text like "Fixes #")

@spena spena requested review from vcrfxia and a team July 24, 2020 20:33
Copy link
Contributor

@vcrfxia vcrfxia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with some questions inline. Thanks!

@@ -222,4 +225,50 @@ private BackupReplayFile newReplayFile() {
? Optional.of(new BackupReplayFile(latestBakFile))
: Optional.empty();
}

private void ensureDirectoryExists(final File backupsDir) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we de-dup this code from enforceStreamStateDirAvailability() in KsqlServerMain? Not required if it's annoying to de-dup (especially since we're trying to keep this patch small in order to cherry-pick) but it's weird to me that we have the same code in two places.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I see it. But I have the extra step to restrict the permissions to the KSQL server user only. I'd like to do that in the state directory too, but I don't know why the directory is not too restrictive. I'd rather investigate more and do it in another follow-up PR.

}

try {
Files.setPosixFilePermissions(backupsDir.toPath(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to explicitly set permissions here? I see we don't do that for the Kafka Streams state directory. I'm in favor of consistency unless there's a good reason to deviate.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to keep the metastore directory restricted from other uses to access the data. By default, the directory created has drwxrwxr-x which is opened to any user in the system. It's up to the user to specify a directory that has restricted permissions only to the required users, but if KSQL creates it automatically, then I set those here too.

I don't know why the streams state directory is not protected. We might want to do that. I won't do it in this patch until I understand their reason.

);
}

if (!backupsDir.canWrite() || !backupsDir.canRead() || !backupsDir.canExecute()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need execute permissions? I see we have a similar check for the Kafka Streams state directory so I assume there's good reason. Curious what it is.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Directories need to have execute permissions in order to create files in it. By default, a new directory has rwx. If you remove the x, then you get a permissions denied.

$ mkdir /tmp/dir
$ chmod a-x /tmp/dir
$ ls -dl /tmp/dir
drw-rw-r-- 2 sergio sergio 4096 Jul 24 15:46 /tmp/dir
$ echo file > /tmp/dir/file
bash: /tmp/dir/file: Permission denied
$ 

@spena spena merged commit d77d8b7 into confluentinc:master Jul 24, 2020
@spena spena deleted the mkdir_backup_dir branch July 24, 2020 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants